zahen created this revision. zahen added reviewers: rnk, thakis, hans, zturner. Herald added a project: clang. Herald added a subscriber: cfe-commits.
msvc allows a subsequent declaration of a uuid attribute on a struct/class. Mirror this behavior in clang-cl. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D71439 Files: clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/SemaCXX/ms-uuid.cpp Index: clang/test/SemaCXX/ms-uuid.cpp =================================================================== --- clang/test/SemaCXX/ms-uuid.cpp +++ clang/test/SemaCXX/ms-uuid.cpp @@ -106,3 +106,9 @@ } } + +// Test class/struct redeclaration where the subsequent +// declaration has a uuid attribute +struct X{}; + +struct __declspec(uuid("00000000-0000-0000-0000-000000000000")) X; \ No newline at end of file Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -5394,9 +5394,11 @@ if (const auto *UA = D->getAttr<UuidAttr>()) { if (UA->getGuid().equals_lower(Uuid)) return nullptr; - Diag(UA->getLocation(), diag::err_mismatched_uuid); - Diag(CI.getLoc(), diag::note_previous_uuid); - D->dropAttr<UuidAttr>(); + if (!UA->getGuid().empty()) { + Diag(UA->getLocation(), diag::err_mismatched_uuid); + Diag(CI.getLoc(), diag::note_previous_uuid); + D->dropAttr<UuidAttr>(); + } } return ::new (Context) UuidAttr(Context, CI, Uuid); Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -2678,6 +2678,10 @@ // C's _Noreturn is allowed to be added to a function after it is defined. ++I; continue; + } else if (isa<UuidAttr>(NewAttribute)) { + // msvc will allow a subsequent definition to add an uuid to a class + ++I; + continue; } else if (const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) { if (AA->isAlignas()) { // C++11 [dcl.align]p6:
Index: clang/test/SemaCXX/ms-uuid.cpp =================================================================== --- clang/test/SemaCXX/ms-uuid.cpp +++ clang/test/SemaCXX/ms-uuid.cpp @@ -106,3 +106,9 @@ } } + +// Test class/struct redeclaration where the subsequent +// declaration has a uuid attribute +struct X{}; + +struct __declspec(uuid("00000000-0000-0000-0000-000000000000")) X; \ No newline at end of file Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -5394,9 +5394,11 @@ if (const auto *UA = D->getAttr<UuidAttr>()) { if (UA->getGuid().equals_lower(Uuid)) return nullptr; - Diag(UA->getLocation(), diag::err_mismatched_uuid); - Diag(CI.getLoc(), diag::note_previous_uuid); - D->dropAttr<UuidAttr>(); + if (!UA->getGuid().empty()) { + Diag(UA->getLocation(), diag::err_mismatched_uuid); + Diag(CI.getLoc(), diag::note_previous_uuid); + D->dropAttr<UuidAttr>(); + } } return ::new (Context) UuidAttr(Context, CI, Uuid); Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -2678,6 +2678,10 @@ // C's _Noreturn is allowed to be added to a function after it is defined. ++I; continue; + } else if (isa<UuidAttr>(NewAttribute)) { + // msvc will allow a subsequent definition to add an uuid to a class + ++I; + continue; } else if (const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) { if (AA->isAlignas()) { // C++11 [dcl.align]p6:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits