Skip to content

Commit 5de8947

Browse files
C++: Fixed generic function false positive (#3043)
1 parent 4e9338a commit 5de8947

File tree

3 files changed

+128
-2
lines changed

3 files changed

+128
-2
lines changed

components/prism-cpp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
Prism.languages.insertBefore('cpp', 'keyword', {
6363
'generic-function': {
64-
pattern: /\b[a-z_]\w*\s*<(?:[^<>]|<(?:[^<>])*>)*>(?=\s*\()/i,
64+
pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
6565
inside: {
6666
'function': /^\w+/,
6767
'generic': {

components/prism-cpp.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/cpp/issue3042.test

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
class Foo
2+
{
3+
public:
4+
5+
friend bool operator== (const Foo& f1, const Foo& f2);
6+
friend bool operator!= (const Foo& f1, const Foo& f2);
7+
8+
friend bool operator< (const Foo& f1, const Foo& f2);
9+
friend bool operator> (const Foo& f1, const Foo& f2);
10+
11+
friend bool operator<= (const Foo& f1, const Foo& f2);
12+
friend bool operator>= (const Foo& f1, const Foo& f2);
13+
};
14+
15+
----------------------------------------------------
16+
17+
[
18+
["keyword", "class"], ["class-name", "Foo"],
19+
["punctuation", "{"],
20+
["keyword", "public"], ["operator", ":"],
21+
22+
["keyword", "friend"],
23+
["keyword", "bool"],
24+
["keyword", "operator"],
25+
["operator", "=="],
26+
["punctuation", "("],
27+
["keyword", "const"],
28+
" Foo",
29+
["operator", "&"],
30+
" f1",
31+
["punctuation", ","],
32+
["keyword", "const"],
33+
" Foo",
34+
["operator", "&"],
35+
" f2",
36+
["punctuation", ")"],
37+
["punctuation", ";"],
38+
39+
["keyword", "friend"],
40+
["keyword", "bool"],
41+
["keyword", "operator"],
42+
["operator", "!="],
43+
["punctuation", "("],
44+
["keyword", "const"],
45+
" Foo",
46+
["operator", "&"],
47+
" f1",
48+
["punctuation", ","],
49+
["keyword", "const"],
50+
" Foo",
51+
["operator", "&"],
52+
" f2",
53+
["punctuation", ")"],
54+
["punctuation", ";"],
55+
56+
["keyword", "friend"],
57+
["keyword", "bool"],
58+
["keyword", "operator"],
59+
["operator", "<"],
60+
["punctuation", "("],
61+
["keyword", "const"],
62+
" Foo",
63+
["operator", "&"],
64+
" f1",
65+
["punctuation", ","],
66+
["keyword", "const"],
67+
" Foo",
68+
["operator", "&"],
69+
" f2",
70+
["punctuation", ")"],
71+
["punctuation", ";"],
72+
73+
["keyword", "friend"],
74+
["keyword", "bool"],
75+
["keyword", "operator"],
76+
["operator", ">"],
77+
["punctuation", "("],
78+
["keyword", "const"],
79+
" Foo",
80+
["operator", "&"],
81+
" f1",
82+
["punctuation", ","],
83+
["keyword", "const"],
84+
" Foo",
85+
["operator", "&"],
86+
" f2",
87+
["punctuation", ")"],
88+
["punctuation", ";"],
89+
90+
["keyword", "friend"],
91+
["keyword", "bool"],
92+
["keyword", "operator"],
93+
["operator", "<="],
94+
["punctuation", "("],
95+
["keyword", "const"],
96+
" Foo",
97+
["operator", "&"],
98+
" f1",
99+
["punctuation", ","],
100+
["keyword", "const"],
101+
" Foo",
102+
["operator", "&"],
103+
" f2",
104+
["punctuation", ")"],
105+
["punctuation", ";"],
106+
107+
["keyword", "friend"],
108+
["keyword", "bool"],
109+
["keyword", "operator"],
110+
["operator", ">="],
111+
["punctuation", "("],
112+
["keyword", "const"],
113+
" Foo",
114+
["operator", "&"],
115+
" f1",
116+
["punctuation", ","],
117+
["keyword", "const"],
118+
" Foo",
119+
["operator", "&"],
120+
" f2",
121+
["punctuation", ")"],
122+
["punctuation", ";"],
123+
124+
["punctuation", "}"],
125+
["punctuation", ";"]
126+
]

0 commit comments

Comments
 (0)