-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3602 from masatake/c++--consteval
C++,C: record consteval, constinit, thread_local, and __thread to properties: field
- Loading branch information
Showing
17 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--sort=no | ||
--kinds-c=*-{parameter} | ||
--fields=+x | ||
--fields-c=+{properties} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
i input.c /^__thread int i;$/;" v typeref:typename:int properties:thread_local | ||
s input.c /^extern __thread struct state s;$/;" x typeref:struct:state properties:extern,thread_local | ||
p input.c /^static __thread char *p;$/;" v typeref:typename:char * file: properties:static,thread_local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* Taken from https://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-Local.html#Thread-Local */ | ||
__thread int i; | ||
extern __thread struct state s; | ||
static __thread char *p; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--sort=no | ||
--kinds-c++=*-{parameter} | ||
--fields=+x | ||
--fields-c++=+{properties} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sqr input.cc /^consteval int sqr(int n)$/;" f typeref:typename:int properties:consteval | ||
r input.cc /^constexpr int r = sqr(100); \/\/ OK$/;" v typeref:typename:int properties:constexpr | ||
x input.cc /^int x = 100;$/;" v typeref:typename:int | ||
r2 input.cc /^int r2 = sqr(x); \/\/ Error: Call does not produce a constant$/;" v typeref:typename:int | ||
sqrsqr input.cc /^consteval int sqrsqr(int n)$/;" f typeref:typename:int properties:consteval | ||
dblsqr input.cc /^constexpr int dblsqr(int n)$/;" f typeref:typename:int properties:constexpr | ||
f input.cc /^consteval int f() { return 42; }$/;" f typeref:typename:int properties:consteval | ||
g input.cc /^consteval auto g() { return &f; }$/;" f typeref:typename:auto properties:consteval | ||
h input.cc /^consteval int h(int (*p)() = g()) { return p(); }$/;" f typeref:typename:int properties:consteval |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Taken from https://en.cppreference.com/w/cpp/language/consteval | ||
consteval int sqr(int n) | ||
{ | ||
return n*n; | ||
} | ||
constexpr int r = sqr(100); // OK | ||
|
||
int x = 100; | ||
int r2 = sqr(x); // Error: Call does not produce a constant | ||
|
||
consteval int sqrsqr(int n) | ||
{ | ||
return sqr(sqr(n)); // Not a constant expression at this point, but OK | ||
} | ||
|
||
constexpr int dblsqr(int n) | ||
{ | ||
return 2 * sqr(n); // Error: Enclosing function is not consteval | ||
// and sqr(n) is not a constant | ||
} | ||
|
||
consteval int f() { return 42; } | ||
consteval auto g() { return &f; } | ||
consteval int h(int (*p)() = g()) { return p(); } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--sort=no | ||
--kinds-c++=*-{parameter} | ||
--fields=+x | ||
--fields-c++=+{properties} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
g input.cc /^const char *g() { return "dynamic initialization"; }$/;" f typeref:typename:const char * | ||
f input.cc /^constexpr const char *f(bool p) { return p ? "constant initializer" : g(); }$/;" f typeref:typename:const char * properties:constexpr | ||
c input.cc /^constinit const char *c = f(true); \/\/ OK$/;" v typeref:typename:const char * properties:constinit | ||
x input.cc /^extern thread_local constinit int x;$/;" x typeref:typename:int properties:extern,constinit,thread_local | ||
f input.cc /^int f() { return x; } \/\/ no check of a guard variable needed$/;" f typeref:typename:int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Taken from https://en.cppreference.com/w/cpp/language/constinit | ||
const char *g() { return "dynamic initialization"; } | ||
constexpr const char *f(bool p) { return p ? "constant initializer" : g(); } | ||
|
||
constinit const char *c = f(true); // OK | ||
|
||
extern thread_local constinit int x; | ||
int f() { return x; } // no check of a guard variable needed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters