Skip to content

Commit bec7905

Browse files
authored
Merge pull request #3602 from masatake/c++--consteval
C++,C: record consteval, constinit, thread_local, and __thread to properties: field
2 parents b2588fe + caf1bd5 commit bec7905

File tree

17 files changed

+124
-2
lines changed

17 files changed

+124
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--sort=no
2+
--kinds-c=*-{parameter}
3+
--fields=+x
4+
--fields-c=+{properties}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
i input.c /^__thread int i;$/;" v typeref:typename:int properties:thread_local
2+
s input.c /^extern __thread struct state s;$/;" x typeref:struct:state properties:extern,thread_local
3+
p input.c /^static __thread char *p;$/;" v typeref:typename:char * file: properties:static,thread_local
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Taken from https://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-Local.html#Thread-Local */
2+
__thread int i;
3+
extern __thread struct state s;
4+
static __thread char *p;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--sort=no
2+
--kinds-c++=*-{parameter}
3+
--fields=+x
4+
--fields-c++=+{properties}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sqr input.cc /^consteval int sqr(int n)$/;" f typeref:typename:int properties:consteval
2+
r input.cc /^constexpr int r = sqr(100); \/\/ OK$/;" v typeref:typename:int properties:constexpr
3+
x input.cc /^int x = 100;$/;" v typeref:typename:int
4+
r2 input.cc /^int r2 = sqr(x); \/\/ Error: Call does not produce a constant$/;" v typeref:typename:int
5+
sqrsqr input.cc /^consteval int sqrsqr(int n)$/;" f typeref:typename:int properties:consteval
6+
dblsqr input.cc /^constexpr int dblsqr(int n)$/;" f typeref:typename:int properties:constexpr
7+
f input.cc /^consteval int f() { return 42; }$/;" f typeref:typename:int properties:consteval
8+
g input.cc /^consteval auto g() { return &f; }$/;" f typeref:typename:auto properties:consteval
9+
h input.cc /^consteval int h(int (*p)() = g()) { return p(); }$/;" f typeref:typename:int properties:consteval
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Taken from https://en.cppreference.com/w/cpp/language/consteval
2+
consteval int sqr(int n)
3+
{
4+
return n*n;
5+
}
6+
constexpr int r = sqr(100); // OK
7+
8+
int x = 100;
9+
int r2 = sqr(x); // Error: Call does not produce a constant
10+
11+
consteval int sqrsqr(int n)
12+
{
13+
return sqr(sqr(n)); // Not a constant expression at this point, but OK
14+
}
15+
16+
constexpr int dblsqr(int n)
17+
{
18+
return 2 * sqr(n); // Error: Enclosing function is not consteval
19+
// and sqr(n) is not a constant
20+
}
21+
22+
consteval int f() { return 42; }
23+
consteval auto g() { return &f; }
24+
consteval int h(int (*p)() = g()) { return p(); }
25+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--sort=no
2+
--kinds-c++=*-{parameter}
3+
--fields=+x
4+
--fields-c++=+{properties}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
g input.cc /^const char *g() { return "dynamic initialization"; }$/;" f typeref:typename:const char *
2+
f input.cc /^constexpr const char *f(bool p) { return p ? "constant initializer" : g(); }$/;" f typeref:typename:const char * properties:constexpr
3+
c input.cc /^constinit const char *c = f(true); \/\/ OK$/;" v typeref:typename:const char * properties:constinit
4+
x input.cc /^extern thread_local constinit int x;$/;" x typeref:typename:int properties:extern,constinit,thread_local
5+
f input.cc /^int f() { return x; } \/\/ no check of a guard variable needed$/;" f typeref:typename:int
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Taken from https://en.cppreference.com/w/cpp/language/constinit
2+
const char *g() { return "dynamic initialization"; }
3+
constexpr const char *f(bool p) { return p ? "constant initializer" : g(); }
4+
5+
constinit const char *c = f(true); // OK
6+
7+
extern thread_local constinit int x;
8+
int f() { return x; } // no check of a guard variable needed

parsers/cxx/cxx_keyword.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ static CXXKeywordDescriptor g_aCXXKeywordTable[] = {
136136
CXXLanguageCPP,
137137
0
138138
},
139+
{
140+
"__thread",
141+
CXXLanguageC | CXXLanguageCPP,
142+
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordExcludeFromTypeNames,
143+
},
139144
{
140145
"alignas",
141146
CXXLanguageCPP,
@@ -212,11 +217,21 @@ static CXXKeywordDescriptor g_aCXXKeywordTable[] = {
212217
CXXLanguageC | CXXLanguageCPP | CXXLanguageCUDA,
213218
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordFlagMayBePartOfTypeName
214219
},
220+
{
221+
"consteval",
222+
CXXLanguageCPP,
223+
CXXKeywordExcludeFromTypeNames
224+
},
215225
{
216226
"constexpr",
217227
CXXLanguageCPP,
218228
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordExcludeFromTypeNames
219229
},
230+
{
231+
"constinit",
232+
CXXLanguageCPP,
233+
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordExcludeFromTypeNames
234+
},
220235
{
221236
"const_cast",
222237
CXXLanguageCPP,
@@ -465,7 +480,7 @@ static CXXKeywordDescriptor g_aCXXKeywordTable[] = {
465480
{
466481
"thread_local",
467482
CXXLanguageCPP,
468-
CXXKeywordMayAppearInVariableDeclaration
483+
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordExcludeFromTypeNames
469484
},
470485
{
471486
"throw",

0 commit comments

Comments
 (0)