Skip to content

Commit f616464

Browse files
committed
CXX: add "constinit" to "properties:" field
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 92d51a8 commit f616464

File tree

11 files changed

+35
-0
lines changed

11 files changed

+35
-0
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: 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:thread_local int properties:extern,constinit
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ static CXXKeywordDescriptor g_aCXXKeywordTable[] = {
222222
CXXLanguageCPP,
223223
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordExcludeFromTypeNames
224224
},
225+
{
226+
"constinit",
227+
CXXLanguageCPP,
228+
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordExcludeFromTypeNames
229+
},
225230
{
226231
"const_cast",
227232
CXXLanguageCPP,

parsers/cxx/cxx_keyword.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef enum _CXXKeyword
5454
CXXKeywordCONST,
5555
CXXKeywordCONSTEVAL, // (since C++20)
5656
CXXKeywordCONSTEXPR, // (since C++11)
57+
CXXKeywordCONSTINIT, // (since C++20)
5758
CXXKeywordCONST_CAST,
5859
CXXKeywordCONTINUE,
5960
CXXKeywordDECLTYPE, // (since C++11)

parsers/cxx/cxx_parser_block.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,9 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
643643
case CXXKeywordCONSTEVAL:
644644
g_cxx.uKeywordState |= CXXParserKeywordStateSeenConsteval;
645645
break;
646+
case CXXKeywordCONSTINIT:
647+
g_cxx.uKeywordState |= CXXParserKeywordStateSeenConstinit;
648+
break;
646649
default:
647650
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenTypedef)
648651
{

parsers/cxx/cxx_parser_function.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,7 @@ int cxxParserEmitFunctionTags(
17341734
uProperties |= CXXTagPropertyConstexpr;
17351735
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenConsteval)
17361736
uProperties |= CXXTagPropertyConsteval;
1737+
// constinit is not here; it is for variables.
17371738
if(pInfo->pSignatureConst)
17381739
uProperties |= CXXTagPropertyConst;
17391740
if(pInfo->uFlags & CXXFunctionSignatureInfoPure)

parsers/cxx/cxx_parser_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ typedef enum _CXXParserKeywordState
288288
CXXParserKeywordStateSeenConstexpr = (1 << 13),
289289
// "consteval" has been seen
290290
CXXParserKeywordStateSeenConsteval = (1 << 14),
291+
// "constinit" has been seen
292+
CXXParserKeywordStateSeenConstinit = (1 << 15),
291293
} CXXParserKeywordState;
292294

293295
#define CXX_PARSER_MAXIMUM_NESTING_LEVELS 1024

parsers/cxx/cxx_parser_variable.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF
759759
// uProperties |= CXXTagPropertyVolatile;
760760
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenConstexpr)
761761
uProperties |= CXXTagPropertyConstexpr;
762+
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenConstinit)
763+
uProperties |= CXXTagPropertyConstinit;
762764
// consteval is not here; it is for functions.
763765

764766
pszProperties = cxxTagSetProperties(uProperties);

parsers/cxx/cxx_tag.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ vString * cxxTagSetProperties(unsigned int uProperties)
374374
ADD_PROPERTY("constexpr");
375375
if (uProperties & CXXTagPropertyConsteval)
376376
ADD_PROPERTY("consteval");
377+
if (uProperties & CXXTagPropertyConstinit)
378+
ADD_PROPERTY("constinit");
377379

378380
cxxTagSetField(CXXTagFieldProperties,vStringValue(pszProperties),false);
379381

0 commit comments

Comments
 (0)