r316310 - For better compatibility with C++11 and C++14, emit a nondiscardable definition
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 22 20:58:34 PDT 2017
Author: rsmith
Date: Sun Oct 22 20:58:34 2017
New Revision: 316310
URL: http://llvm.org/viewvc/llvm-project?rev=316310&view=rev
Log:
For better compatibility with C++11 and C++14, emit a nondiscardable definition
of a static constexpr data member if it's defined 'constexpr' out of line, not
only if it's defined 'constexpr' in the class.
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=316310&r1=316309&r2=316310&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Oct 22 20:58:34 2017
@@ -5635,14 +5635,14 @@ ASTContext::getInlineVariableDefinitionK
// In almost all cases, it's a weak definition.
auto *First = VD->getFirstDecl();
- if (!First->isConstexpr() || First->isInlineSpecified() ||
- !VD->isStaticDataMember())
+ if (First->isInlineSpecified() || !First->isStaticDataMember())
return InlineVariableDefinitionKind::Weak;
// If there's a file-context declaration in this translation unit, it's a
// non-discardable definition.
for (auto *D : VD->redecls())
- if (D->getLexicalDeclContext()->isFileContext())
+ if (D->getLexicalDeclContext()->isFileContext() &&
+ !D->isInlineSpecified() && (D->isConstexpr() || First->isConstexpr()))
return InlineVariableDefinitionKind::Strong;
// If we've not seen one yet, we don't know.
Modified: cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp?rev=316310&r1=316309&r2=316310&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp Sun Oct 22 20:58:34 2017
@@ -31,18 +31,28 @@ struct compat {
static constexpr int b = 2;
static constexpr int c = 3;
static inline constexpr int d = 4;
+ static const int e = 5;
+ static const int f = 6;
+ static const int g = 7;
};
const int &compat_use_before_redecl = compat::b;
const int compat::a;
const int compat::b;
const int compat::c;
const int compat::d;
+const int compat::e;
+constexpr int compat::f;
+constexpr inline int compat::g;
const int &compat_use_after_redecl1 = compat::c;
const int &compat_use_after_redecl2 = compat::d;
-// CHECK: @_ZN6compat1bE = weak_odr constant i32 2
-// CHECK: @_ZN6compat1aE = weak_odr constant i32 1
-// CHECK: @_ZN6compat1cE = weak_odr constant i32 3
-// CHECK: @_ZN6compat1dE = linkonce_odr constant i32 4
+const int &compat_use_after_redecl3 = compat::g;
+// CHECK-DAG: @_ZN6compat1bE = weak_odr constant i32 2
+// CHECK-DAG: @_ZN6compat1aE = weak_odr constant i32 1
+// CHECK-DAG: @_ZN6compat1cE = weak_odr constant i32 3
+// CHECK-DAG: @_ZN6compat1dE = linkonce_odr constant i32 4
+// CHECK-DAG: @_ZN6compat1eE = constant i32 5
+// CHECK-DAG: @_ZN6compat1fE = weak_odr constant i32 6
+// CHECK-DAG: @_ZN6compat1gE = linkonce_odr constant i32 7
template<typename T> struct X {
static int a;
More information about the cfe-commits
mailing list