@@ -1172,6 +1172,80 @@ TEST_F(LibclangParseTest, UnaryOperator) {
1172
1172
});
1173
1173
}
1174
1174
1175
+ TEST_F (LibclangParseTest, VisitStaticAssertDecl_noMessage) {
1176
+ const char testSource[] = R"cpp( static_assert(true))cpp" ;
1177
+ std::string fileName = " main.cpp" ;
1178
+ WriteFile (fileName, testSource);
1179
+ const char *Args[] = {" -xc++" };
1180
+ ClangTU = clang_parseTranslationUnit (Index, fileName.c_str (), Args, 1 ,
1181
+ nullptr , 0 , TUFlags);
1182
+
1183
+ std::optional<CXCursor> staticAssertCsr;
1184
+ Traverse ([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
1185
+ if (cursor.kind == CXCursor_StaticAssert) {
1186
+ staticAssertCsr.emplace (cursor);
1187
+ return CXChildVisit_Break;
1188
+ }
1189
+ return CXChildVisit_Recurse;
1190
+ });
1191
+ ASSERT_TRUE (staticAssertCsr.has_value ());
1192
+ Traverse (*staticAssertCsr, [](CXCursor cursor, CXCursor parent) {
1193
+ EXPECT_EQ (cursor.kind , CXCursor_CXXBoolLiteralExpr);
1194
+ return CXChildVisit_Break;
1195
+ });
1196
+ EXPECT_EQ (fromCXString (clang_getCursorSpelling (*staticAssertCsr)), " " );
1197
+ }
1198
+
1199
+ TEST_F (LibclangParseTest, VisitStaticAssertDecl_exprMessage) {
1200
+ const char testSource[] = R"cpp(
1201
+ template <unsigned s>
1202
+ constexpr unsigned size(const char (&)[s])
1203
+ {
1204
+ return s - 1;
1205
+ }
1206
+
1207
+ struct Message {
1208
+ static constexpr char message[] = "Hello World!";
1209
+ constexpr const char* data() const { return message;}
1210
+ constexpr unsigned size() const
1211
+ {
1212
+ return ::size(message);
1213
+ }
1214
+ };
1215
+ Message message;
1216
+ static_assert(true, message);
1217
+ )cpp" ;
1218
+ std::string fileName = " main.cpp" ;
1219
+ WriteFile (fileName, testSource);
1220
+ const char *Args[] = {" -xc++" , " -std=c++26" };
1221
+ ClangTU = clang_parseTranslationUnit (Index, fileName.c_str (), Args,
1222
+ std::size (Args), nullptr , 0 , TUFlags);
1223
+ ASSERT_EQ (clang_getNumDiagnostics (ClangTU), 0 );
1224
+ std::optional<CXCursor> staticAssertCsr;
1225
+ Traverse ([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
1226
+ if (cursor.kind == CXCursor_StaticAssert) {
1227
+ staticAssertCsr.emplace (cursor);
1228
+ }
1229
+ return CXChildVisit_Continue;
1230
+ });
1231
+ ASSERT_TRUE (staticAssertCsr.has_value ());
1232
+ size_t argCnt = 0 ;
1233
+ Traverse (*staticAssertCsr, [&argCnt](CXCursor cursor, CXCursor parent) {
1234
+ switch (argCnt) {
1235
+ case 0 :
1236
+ EXPECT_EQ (cursor.kind , CXCursor_CXXBoolLiteralExpr);
1237
+ break ;
1238
+ case 1 :
1239
+ EXPECT_EQ (cursor.kind , CXCursor_DeclRefExpr);
1240
+ break ;
1241
+ }
1242
+ ++argCnt;
1243
+ return CXChildVisit_Continue;
1244
+ });
1245
+ ASSERT_EQ (argCnt, 2 );
1246
+ EXPECT_EQ (fromCXString (clang_getCursorSpelling (*staticAssertCsr)), " " );
1247
+ }
1248
+
1175
1249
class LibclangRewriteTest : public LibclangParseTest {
1176
1250
public:
1177
1251
CXRewriter Rew = nullptr ;
0 commit comments