r214267 - Not all instantiated variable is odr-used. Do not mark non-odr-used variable template specializations as such.
Larisse Voufo
lvoufo at google.com
Tue Jul 29 17:49:55 PDT 2014
Author: lvoufo
Date: Tue Jul 29 19:49:55 2014
New Revision: 214267
URL: http://llvm.org/viewvc/llvm-project?rev=214267&view=rev
Log:
Not all instantiated variable is odr-used. Do not mark non-odr-used variable template specializations as such.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/PR10177.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=214267&r1=214266&r2=214267&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jul 29 19:49:55 2014
@@ -12440,6 +12440,7 @@ static void DoMarkVarDeclReferenced(Sema
Var->setReferenced();
TemplateSpecializationKind TSK = Var->getTemplateSpecializationKind();
+ bool MarkODRUsed = true;
// If the context is not potentially evaluated, this is not an odr-use and
// does not trigger instantiation.
@@ -12475,6 +12476,9 @@ static void DoMarkVarDeclReferenced(Sema
if (!isTemplateInstantiation(TSK))
return;
+
+ // Instantiate, but do not mark as odr-used, variable templates.
+ MarkODRUsed = false;
}
VarTemplateSpecializationDecl *VarSpec =
@@ -12525,6 +12529,8 @@ static void DoMarkVarDeclReferenced(Sema
}
}
+ if(!MarkODRUsed) return;
+
// Per C++11 [basic.def.odr], a variable is odr-used "unless it satisfies
// the requirements for appearing in a constant expression (5.19) and, if
// it is an object, the lvalue-to-rvalue conversion (4.1)
Modified: cfe/trunk/test/SemaCXX/PR10177.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR10177.cpp?rev=214267&r1=214266&r2=214267&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/PR10177.cpp (original)
+++ cfe/trunk/test/SemaCXX/PR10177.cpp Tue Jul 29 19:49:55 2014
@@ -1,4 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++1y -verify %s -DCXX1Y
+
+#ifndef CXX1Y
template<typename T, typename U, U> using alias_ref = T;
template<typename T, typename U, U> void func_ref() {}
@@ -21,6 +24,7 @@ void f() {
(void)class_ref<int, int&, U<2>::a>(); // expected-note {{here}}
};
+
template<int N>
void fi() {
(void)alias_ref<int, int&, U<N>::a>(); // expected-note {{here}}
@@ -45,3 +49,11 @@ namespace N {
int j = f<int>();
}
+#else
+// expected-no-diagnostics
+
+namespace { template<typename> extern int n; }
+template<typename T> int g() { return n<int>; }
+
+#endif
+
More information about the cfe-commits
mailing list