-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added list of false positiitives #3999
base: main
Are you sure you want to change the base?
Changes from all commits
913d32d
89853e2
81079eb
2b3fa7b
68619d1
0b50faf
d14ec57
6e14ee8
c7eeeca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -415,6 +415,14 @@ export default function(hljs) { | |
_type_hints: TYPE_HINTS | ||
}; | ||
|
||
const allKeywords = [ | ||
...CPP_KEYWORDS.type, | ||
...CPP_KEYWORDS.keyword, | ||
...CPP_KEYWORDS.literal, | ||
...CPP_KEYWORDS.built_in, | ||
...CPP_KEYWORDS._type_hints | ||
]; | ||
|
||
const FUNCTION_DISPATCH = { | ||
className: 'function.dispatch', | ||
relevance: 0, | ||
|
@@ -423,15 +431,11 @@ export default function(hljs) { | |
_hint: FUNCTION_HINTS }, | ||
begin: regex.concat( | ||
/\b/, | ||
/(?!decltype)/, | ||
/(?!if)/, | ||
/(?!for)/, | ||
/(?!switch)/, | ||
/(?!while)/, | ||
// adds all keywords dynamically | ||
...allKeywords.map(keyword => new RegExp(`(?!${keyword})`)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually don't we only care about keywords here that can potentially have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can ignore this for now since I already said this was ready but need your author link... |
||
hljs.IDENT_RE, | ||
regex.lookahead(/(<[^<>]+>|)\s*\(/)) | ||
}; | ||
|
||
const EXPRESSION_CONTAINS = [ | ||
FUNCTION_DISPATCH, | ||
PREPROCESSOR, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<span class="hljs-keyword">alignas</span>(<span class="hljs-number">16</span>) <span class="hljs-type">char</span> aligned_buffer[<span class="hljs-number">1024</span>]; | ||
<span class="hljs-keyword">alignof</span>(<span class="hljs-keyword">decltype</span>(aligned_buffer)) | ||
<span class="hljs-keyword">asm</span>(<span class="hljs-string">"movl $1, %eax"</span>); | ||
<span class="hljs-keyword">try</span> { | ||
<span class="hljs-keyword">throw</span> std::<span class="hljs-built_in">runtime_error</span>(<span class="hljs-string">"An exception occurred"</span>); | ||
} <span class="hljs-keyword">catch</span> (<span class="hljs-type">const</span> std::exception& e) { | ||
std::cout << <span class="hljs-string">"Caught exception: "</span> << e.<span class="hljs-built_in">what</span>() << std::endl; | ||
} | ||
<span class="hljs-type">const</span> <span class="hljs-type">int</span>* p = <span class="hljs-literal">nullptr</span>; | ||
<span class="hljs-type">int</span>* mutable_p = <span class="hljs-keyword">const_cast</span><<span class="hljs-type">int</span>*>(p); | ||
<span class="hljs-type">int</span> x = <span class="hljs-number">5</span>; | ||
<span class="hljs-keyword">decltype</span>(x) y = <span class="hljs-number">10</span>; | ||
Animal* animal = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Dog</span>(); | ||
<span class="hljs-keyword">if</span> (Dog* dog = <span class="hljs-keyword">dynamic_cast</span><Dog*>(animal)) { | ||
std::cout << <span class="hljs-string">"Dynamic cast successful"</span> << std::endl; | ||
} <span class="hljs-keyword">else</span> { | ||
std::cout << <span class="hljs-string">"Dynamic cast failed"</span> << std::endl; | ||
} | ||
<span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-type">int</span> a, <span class="hljs-type">int</span> b)</span> <span class="hljs-keyword">noexcept</span> </span>{ | ||
<span class="hljs-keyword">return</span> a + b; | ||
} | ||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">noexcept</span>(<span class="hljs-built_in">add</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>))) { | ||
<span class="hljs-comment">// The add function will not throw an exception.</span> | ||
} <span class="hljs-keyword">else</span> { | ||
<span class="hljs-comment">// The add function may throw an exception.</span> | ||
} | ||
<span class="hljs-type">int</span> value = <span class="hljs-number">10</span>; | ||
<span class="hljs-type">double</span>* ptr = <span class="hljs-keyword">reinterpret_cast</span><<span class="hljs-type">double</span>*>(&value); | ||
std::cout << <span class="hljs-string">"Size of int: "</span> << <span class="hljs-keyword">sizeof</span>(<span class="hljs-type">int</span>) << <span class="hljs-string">" bytes"</span> << std::endl; | ||
<span class="hljs-keyword">static_assert</span>(<span class="hljs-keyword">sizeof</span>(<span class="hljs-type">int</span>) == <span class="hljs-number">4</span>, <span class="hljs-string">"int must be 4 bytes"</span>); | ||
<span class="hljs-type">float</span> z = <span class="hljs-keyword">static_cast</span><<span class="hljs-type">float</span>>(<span class="hljs-number">10</span>); | ||
<span class="hljs-type">int</span> choice = <span class="hljs-number">2</span>; | ||
<span class="hljs-keyword">switch</span>(choice) { | ||
<span class="hljs-keyword">case</span> <span class="hljs-number">1</span>: | ||
std::cout << <span class="hljs-string">"Choice is 1"</span> << std::endl; | ||
<span class="hljs-keyword">break</span>; | ||
<span class="hljs-keyword">case</span> <span class="hljs-number">2</span>: | ||
std::cout << <span class="hljs-string">"Choice is 2"</span> << std::endl; | ||
<span class="hljs-keyword">break</span>; | ||
<span class="hljs-keyword">default</span>: | ||
std::cout << <span class="hljs-string">"Choice is not 1 or 2"</span> << std::endl; | ||
} | ||
std::cout << <span class="hljs-string">"Type of x: "</span> << <span class="hljs-keyword">typeid</span>(x).<span class="hljs-built_in">name</span>() << std::endl; | ||
<span class="hljs-type">int</span> i = <span class="hljs-number">0</span>; | ||
<span class="hljs-keyword">while</span>(i < <span class="hljs-number">5</span>) { | ||
std::cout << <span class="hljs-string">"Iteration "</span> << i << std::endl; | ||
i++; | ||
} | ||
<span class="hljs-comment">// requires</span> | ||
<span class="hljs-keyword">template</span><<span class="hljs-keyword">class</span> <span class="hljs-title class_">T</span>> | ||
<span class="hljs-keyword">concept</span> dereferenceable = | ||
<span class="hljs-keyword">requires</span> { <span class="hljs-keyword">typename</span> <span class="hljs-type">iter_value_t</span><I>; } <span class="hljs-function"><span class="hljs-keyword">and</span> | ||
<span class="hljs-title">requires</span><span class="hljs-params">(I i)</span> </span>{ | ||
*i; | ||
}; | ||
|
||
<span class="hljs-comment">// explicit</span> | ||
<span class="hljs-keyword">template</span><<span class="hljs-keyword">class</span> <span class="hljs-title class_">T</span>> | ||
<span class="hljs-keyword">struct</span> <span class="hljs-title class_">S</span> { | ||
<span class="hljs-keyword">explicit</span>(weakly_incrementable<T>) <span class="hljs-built_in">S</span>(); | ||
}; | ||
|
||
<span class="hljs-comment">// auto, operators</span> | ||
<span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> | ||
</span>{ | ||
<span class="hljs-keyword">auto</span> x = <span class="hljs-keyword">auto</span>(<span class="hljs-number">0</span>); | ||
x bitand_eq x; <span class="hljs-comment">// needs to be added too</span> | ||
<span class="hljs-function">x <span class="hljs-title">bitand_eq</span> <span class="hljs-params">(x)</span></span>; | ||
x bitor_eq x; <span class="hljs-comment">// needs to be added too</span> | ||
<span class="hljs-function">x <span class="hljs-title">bitor_eq</span> <span class="hljs-params">(x)</span></span>; | ||
x <span class="hljs-keyword">xor</span> x; | ||
<span class="hljs-function">x <span class="hljs-title">xor</span> <span class="hljs-params">(x)</span></span>; | ||
x <span class="hljs-keyword">and</span> x; | ||
<span class="hljs-function">x <span class="hljs-title">and</span> <span class="hljs-params">(x)</span></span>; | ||
x <span class="hljs-keyword">or</span> x; | ||
<span class="hljs-function">x <span class="hljs-title">or</span> <span class="hljs-params">(x)</span></span>; | ||
x <span class="hljs-keyword">bitand</span> x; | ||
<span class="hljs-function">x <span class="hljs-title">bitand</span> <span class="hljs-params">(x)</span></span>; | ||
x <span class="hljs-keyword">bitor</span> x; | ||
<span class="hljs-function">x <span class="hljs-title">bitor</span> <span class="hljs-params">(x)</span></span>; | ||
x <span class="hljs-keyword">not_eq</span> x; | ||
<span class="hljs-function">x <span class="hljs-title">not_eq</span> <span class="hljs-params">(x)</span></span>; | ||
<span class="hljs-keyword">not</span> x; | ||
<span class="hljs-keyword">not</span> (x); | ||
<span class="hljs-keyword">compl</span> x; | ||
<span class="hljs-keyword">compl</span> (x); | ||
<span class="hljs-keyword">co_await</span> x; | ||
<span class="hljs-keyword">co_await</span> (x); | ||
<span class="hljs-keyword">co_return</span> x; | ||
<span class="hljs-keyword">co_return</span> (x); | ||
<span class="hljs-keyword">co_yield</span> x; | ||
<span class="hljs-keyword">co_yield</span> (x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
alignas(16) char aligned_buffer[1024]; | ||
alignof(decltype(aligned_buffer)) | ||
asm("movl $1, %eax"); | ||
try { | ||
throw std::runtime_error("An exception occurred"); | ||
} catch (const std::exception& e) { | ||
std::cout << "Caught exception: " << e.what() << std::endl; | ||
} | ||
const int* p = nullptr; | ||
int* mutable_p = const_cast<int*>(p); | ||
int x = 5; | ||
decltype(x) y = 10; | ||
Animal* animal = new Dog(); | ||
if (Dog* dog = dynamic_cast<Dog*>(animal)) { | ||
std::cout << "Dynamic cast successful" << std::endl; | ||
} else { | ||
std::cout << "Dynamic cast failed" << std::endl; | ||
} | ||
int add(int a, int b) noexcept { | ||
return a + b; | ||
} | ||
if (noexcept(add(1, 2))) { | ||
// The add function will not throw an exception. | ||
} else { | ||
// The add function may throw an exception. | ||
} | ||
int value = 10; | ||
double* ptr = reinterpret_cast<double*>(&value); | ||
std::cout << "Size of int: " << sizeof(int) << " bytes" << std::endl; | ||
static_assert(sizeof(int) == 4, "int must be 4 bytes"); | ||
float z = static_cast<float>(10); | ||
int choice = 2; | ||
switch(choice) { | ||
case 1: | ||
std::cout << "Choice is 1" << std::endl; | ||
break; | ||
case 2: | ||
std::cout << "Choice is 2" << std::endl; | ||
break; | ||
default: | ||
std::cout << "Choice is not 1 or 2" << std::endl; | ||
} | ||
std::cout << "Type of x: " << typeid(x).name() << std::endl; | ||
int i = 0; | ||
while(i < 5) { | ||
std::cout << "Iteration " << i << std::endl; | ||
i++; | ||
} | ||
// requires | ||
template<class T> | ||
concept dereferenceable = | ||
requires { typename iter_value_t<I>; } and | ||
requires(I i) { | ||
*i; | ||
}; | ||
|
||
// explicit | ||
template<class T> | ||
struct S { | ||
explicit(weakly_incrementable<T>) S(); | ||
}; | ||
|
||
// auto, operators | ||
int main() | ||
{ | ||
auto x = auto(0); | ||
x bitand_eq x; // needs to be added too | ||
x bitand_eq (x); | ||
x bitor_eq x; // needs to be added too | ||
x bitor_eq (x); | ||
x xor x; | ||
x xor (x); | ||
x and x; | ||
x and (x); | ||
x or x; | ||
x or (x); | ||
x bitand x; | ||
x bitand (x); | ||
x bitor x; | ||
x bitor (x); | ||
x not_eq x; | ||
x not_eq (x); | ||
not x; | ||
not (x); | ||
compl x; | ||
compl (x); | ||
co_await x; | ||
co_await (x); | ||
co_return x; | ||
co_return (x); | ||
co_yield x; | ||
co_yield (x); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add your author link below as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping.