From: Larisse Voufo Date: Wed, 30 Jul 2014 00:49:55 +0000 (+0000) Subject: Not all instantiated variable is odr-used. Do not mark non-odr-used variable template... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03cbfe00b66a4958b977e4fe088008770285caca;p=clang Not all instantiated variable is odr-used. Do not mark non-odr-used variable template specializations as such. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214267 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ea5ad77fc0..4675c45f2f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -12440,6 +12440,7 @@ static void DoMarkVarDeclReferenced(Sema &SemaRef, SourceLocation Loc, 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 &SemaRef, SourceLocation Loc, 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 &SemaRef, SourceLocation Loc, } } + 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) diff --git a/test/SemaCXX/PR10177.cpp b/test/SemaCXX/PR10177.cpp index 8093e18e33..e361ff37bc 100644 --- a/test/SemaCXX/PR10177.cpp +++ b/test/SemaCXX/PR10177.cpp @@ -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 using alias_ref = T; template void func_ref() {} @@ -21,6 +24,7 @@ void f() { (void)class_ref::a>(); // expected-note {{here}} }; + template void fi() { (void)alias_ref::a>(); // expected-note {{here}} @@ -45,3 +49,11 @@ namespace N { int j = f(); } +#else +// expected-no-diagnostics + +namespace { template extern int n; } +template int g() { return n; } + +#endif +