[PATCH] D67426: Don't warn about selectany on implicitly inline variables
Reid Kleckner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 12 10:58:22 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb00a49d1b3a1: Don't warn about selectany on implicitly inline variables (authored by rnk).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67426/new/
https://reviews.llvm.org/D67426
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/declspec-selectany.cpp
Index: clang/test/SemaCXX/declspec-selectany.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/declspec-selectany.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-windows-msvc -fdeclspec -verify
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-windows-msvc -fdeclspec -verify
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-scei-ps4 -fdeclspec -verify
+
+// MSVC emits this error too.
+const int __declspec(selectany) test1 = 0; // expected-error {{'selectany' can only be applied to data items with external linkage}}
+
+extern const int test2;
+const int test2 = 42; // expected-note {{previous definition is here}}
+extern __declspec(selectany) const int test2; // expected-warning {{attribute declaration must precede definition}}
+
+extern const int test3;
+const int __declspec(selectany) test3 = 42; // Standard usage.
+
+struct Test4 {
+ static constexpr int sdm = 0;
+};
+__declspec(selectany) constexpr int Test4::sdm; // no warning
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2652,6 +2652,15 @@
--E;
continue;
}
+ } else if (isa<SelectAnyAttr>(NewAttribute) &&
+ cast<VarDecl>(New)->isInline() &&
+ !cast<VarDecl>(New)->isInlineSpecified()) {
+ // Don't warn about applying selectany to implicitly inline variables.
+ // Older compilers and language modes would require the use of selectany
+ // to make such variables inline, and it would have no effect if we
+ // honored it.
+ ++I;
+ continue;
}
S.Diag(NewAttribute->getLocation(),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67426.219950.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190912/07188b89/attachment.bin>
More information about the cfe-commits
mailing list