Skip to content

Commit

Permalink
C++: Fixed generic function false positive (#3043)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Sep 1, 2021
1 parent 4e9338a commit 5de8947
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/prism-cpp.js
Expand Up @@ -61,7 +61,7 @@

Prism.languages.insertBefore('cpp', 'keyword', {
'generic-function': {
pattern: /\b[a-z_]\w*\s*<(?:[^<>]|<(?:[^<>])*>)*>(?=\s*\()/i,
pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
inside: {
'function': /^\w+/,
'generic': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-cpp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 126 additions & 0 deletions tests/languages/cpp/issue3042.test
@@ -0,0 +1,126 @@
class Foo
{
public:

friend bool operator== (const Foo& f1, const Foo& f2);
friend bool operator!= (const Foo& f1, const Foo& f2);

friend bool operator< (const Foo& f1, const Foo& f2);
friend bool operator> (const Foo& f1, const Foo& f2);

friend bool operator<= (const Foo& f1, const Foo& f2);
friend bool operator>= (const Foo& f1, const Foo& f2);
};

----------------------------------------------------

[
["keyword", "class"], ["class-name", "Foo"],
["punctuation", "{"],
["keyword", "public"], ["operator", ":"],

["keyword", "friend"],
["keyword", "bool"],
["keyword", "operator"],
["operator", "=="],
["punctuation", "("],
["keyword", "const"],
" Foo",
["operator", "&"],
" f1",
["punctuation", ","],
["keyword", "const"],
" Foo",
["operator", "&"],
" f2",
["punctuation", ")"],
["punctuation", ";"],

["keyword", "friend"],
["keyword", "bool"],
["keyword", "operator"],
["operator", "!="],
["punctuation", "("],
["keyword", "const"],
" Foo",
["operator", "&"],
" f1",
["punctuation", ","],
["keyword", "const"],
" Foo",
["operator", "&"],
" f2",
["punctuation", ")"],
["punctuation", ";"],

["keyword", "friend"],
["keyword", "bool"],
["keyword", "operator"],
["operator", "<"],
["punctuation", "("],
["keyword", "const"],
" Foo",
["operator", "&"],
" f1",
["punctuation", ","],
["keyword", "const"],
" Foo",
["operator", "&"],
" f2",
["punctuation", ")"],
["punctuation", ";"],

["keyword", "friend"],
["keyword", "bool"],
["keyword", "operator"],
["operator", ">"],
["punctuation", "("],
["keyword", "const"],
" Foo",
["operator", "&"],
" f1",
["punctuation", ","],
["keyword", "const"],
" Foo",
["operator", "&"],
" f2",
["punctuation", ")"],
["punctuation", ";"],

["keyword", "friend"],
["keyword", "bool"],
["keyword", "operator"],
["operator", "<="],
["punctuation", "("],
["keyword", "const"],
" Foo",
["operator", "&"],
" f1",
["punctuation", ","],
["keyword", "const"],
" Foo",
["operator", "&"],
" f2",
["punctuation", ")"],
["punctuation", ";"],

["keyword", "friend"],
["keyword", "bool"],
["keyword", "operator"],
["operator", ">="],
["punctuation", "("],
["keyword", "const"],
" Foo",
["operator", "&"],
" f1",
["punctuation", ","],
["keyword", "const"],
" Foo",
["operator", "&"],
" f2",
["punctuation", ")"],
["punctuation", ";"],

["punctuation", "}"],
["punctuation", ";"]
]

0 comments on commit 5de8947

Please sign in to comment.