File tree Expand file tree Collapse file tree
tests/multi-file/cross_tu_anon_enum_collision Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -408,9 +408,10 @@ std::string GetNamedDeclAsString(const clang::NamedDecl *decl) {
408408 auto name = decl->getDeclName ().isIdentifier () ? decl->getName ().str ()
409409 : decl->getNameAsString ();
410410
411- // Anonymous record
411+ // Anonymous record or enum
412412 if (name.empty () && (clang::isa<clang::RecordDecl>(decl) ||
413- clang::isa<clang::FieldDecl>(decl))) {
413+ clang::isa<clang::FieldDecl>(decl) ||
414+ clang::isa<clang::EnumDecl>(decl))) {
414415 const clang::NamedDecl *target = decl;
415416 if (auto *field = clang::dyn_cast<clang::FieldDecl>(decl)) {
416417 if (auto *record = field->getType ()->getAsRecordDecl ();
Original file line number Diff line number Diff line change @@ -765,7 +765,7 @@ std::string ToString(const clang::NamedDecl *decl) {
765765 }
766766 if (!enum_decl->getIdentifier () &&
767767 !enum_decl->getTypedefNameForAnonDecl ()) {
768- return std::format ( " anon_enum_{} " , GetLineNumber ( enum_decl) );
768+ return GetNamedDeclAsString ( enum_decl);
769769 }
770770 }
771771
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.16 )
2+ project (cross_tu_anon_enum_collision LANGUAGES C )
3+ add_executable (app a.c b.c )
Original file line number Diff line number Diff line change 1+ #include <assert.h>
2+ // anon enum below shares the same declaration line as b.c:enum { BETA = 9 }
3+ enum { ALPHA = 7 };
4+
5+ int b_value (void );
6+
7+ int a_value (void ) {
8+ int x = 0 ;
9+ x |= ALPHA ;
10+ return x ;
11+ }
12+
13+ int main (void ) {
14+ assert (a_value () == 7 );
15+ assert (b_value () == 9 );
16+ return 0 ;
17+ }
Original file line number Diff line number Diff line change 1+ // anon enum below shares the same declaration line as b.c:enum { ALPHA = 7 }
2+
3+ enum { BETA = 9 };
4+
5+ int b_value (void ) {
6+ int x = 0 ;
7+ x |= BETA ;
8+ return x ;
9+ }
You can’t perform that action at this time.
0 commit comments