Skip to content

Commit 0acfc49

Browse files
Zachary Henkelrnk
authored andcommitted
Allow redeclaration of __declspec(uuid)
msvc allows a subsequent declaration of a uuid attribute on a struct/class. Mirror this behavior in clang-cl. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D71439
1 parent 7ca86ee commit 0acfc49

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,6 +2685,10 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) {
26852685
// C's _Noreturn is allowed to be added to a function after it is defined.
26862686
++I;
26872687
continue;
2688+
} else if (isa<UuidAttr>(NewAttribute)) {
2689+
// msvc will allow a subsequent definition to add an uuid to a class
2690+
++I;
2691+
continue;
26882692
} else if (const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
26892693
if (AA->isAlignas()) {
26902694
// C++11 [dcl.align]p6:

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5394,9 +5394,11 @@ UuidAttr *Sema::mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
53945394
if (const auto *UA = D->getAttr<UuidAttr>()) {
53955395
if (UA->getGuid().equals_lower(Uuid))
53965396
return nullptr;
5397-
Diag(UA->getLocation(), diag::err_mismatched_uuid);
5398-
Diag(CI.getLoc(), diag::note_previous_uuid);
5399-
D->dropAttr<UuidAttr>();
5397+
if (!UA->getGuid().empty()) {
5398+
Diag(UA->getLocation(), diag::err_mismatched_uuid);
5399+
Diag(CI.getLoc(), diag::note_previous_uuid);
5400+
D->dropAttr<UuidAttr>();
5401+
}
54005402
}
54015403

54025404
return ::new (Context) UuidAttr(Context, CI, Uuid);

clang/test/SemaCXX/ms-uuid.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,9 @@ void F2() {
106106
}
107107

108108
}
109+
110+
// Test class/struct redeclaration where the subsequent
111+
// declaration has a uuid attribute
112+
struct X{};
113+
114+
struct __declspec(uuid("00000000-0000-0000-0000-000000000000")) X;

0 commit comments

Comments
 (0)