diff --git a/src/languages/cpp.js b/src/languages/cpp.js
index b38f0c30fc..78ac5d5634 100644
--- a/src/languages/cpp.js
+++ b/src/languages/cpp.js
@@ -12,8 +12,11 @@ function(hljs) {
}
var DECLTYPE_AUTO_RE = 'decltype\\(auto\\)'
var NAMESPACE_RE = '[a-zA-Z_]\\w*::'
- // (<.*?>)?
- var FUNCTION_TYPE_RE = '(' + DECLTYPE_AUTO_RE + '|' + optional(NAMESPACE_RE) +'[a-zA-Z_]\\w*)';
+ var TEMPLATE_ARGUMENT_RE = '<.*?>';
+ var FUNCTION_TYPE_RE = '(' +
+ DECLTYPE_AUTO_RE + '|' +
+ optional(NAMESPACE_RE) +'[a-zA-Z_]\\w*' + optional(TEMPLATE_ARGUMENT_RE) +
+ ')';
var CPP_PRIMITIVE_TYPES = {
className: 'keyword',
begin: '\\b[a-z\\d_]*_t\\b'
@@ -139,7 +142,7 @@ function(hljs) {
returnBegin: true, end: /[{;=]/,
excludeEnd: true,
keywords: CPP_KEYWORDS,
- illegal: /[^\w\s\*&:]/,
+ illegal: /[^\w\s\*&:<>]/,
contains: [
{ // to prevent it from being confused as the function title
diff --git a/test/markup/cpp/function-declarations.expect.txt b/test/markup/cpp/function-declarations.expect.txt
index 414721bfc4..5189214025 100644
--- a/test/markup/cpp/function-declarations.expect.txt
+++ b/test/markup/cpp/function-declarations.expect.txt
@@ -10,4 +10,7 @@
B::type test() {};
+
+boost::optional<application> handle_key(application state, key_code key, coord size);
+
test();
diff --git a/test/markup/cpp/function-declarations.txt b/test/markup/cpp/function-declarations.txt
index 318a5b0a33..d196f5ca83 100644
--- a/test/markup/cpp/function-declarations.txt
+++ b/test/markup/cpp/function-declarations.txt
@@ -10,4 +10,7 @@ int8_t Get_Tile_Value() {}
B::type test() {};
+// template
+boost::optional handle_key(application state, key_code key, coord size);
+
test();