[cfe-commits] r155893 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp test/CodeGenCXX/destructors.cpp test/SemaCXX/conversion.cpp
David Blaikie
dblaikie at gmail.com
Mon Apr 30 23:05:57 PDT 2012
Author: dblaikie
Date: Tue May 1 01:05:57 2012
New Revision: 155893
URL: http://llvm.org/viewvc/llvm-project?rev=155893&view=rev
Log:
PR12710 - broken default argument handling for templates.
I broke this in r155838 by not actually instantiating non-dependent default arg
expressions. The motivation for that change was to avoid producing duplicate
conversion warnings for such default args (we produce them once when we parse
the template - there's no need to produce them at each instantiation) but
without actually instantiating the default arg, things break in weird ways.
Technically, I think we could still get the right diagnostic experience without
the bugs if we instantiated the non-dependent args (for non-dependent params
only) immediately, rather than lazily. But I'm not sure if such a refactoring/
change would be desirable so here's the conservative fix for now.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/CodeGenCXX/destructors.cpp
cfe/trunk/test/SemaCXX/conversion.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=155893&r1=155892&r2=155893&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue May 1 01:05:57 2012
@@ -1594,13 +1594,11 @@
} else if (OldParm->hasUnparsedDefaultArg()) {
NewParm->setUnparsedDefaultArg();
UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
- } else if (Expr *Arg = OldParm->getDefaultArg()) {
- if (Arg->isInstantiationDependent() ||
- OldDI->getType()->isInstantiationDependentType())
- NewParm->setUninstantiatedDefaultArg(Arg);
- else
- NewParm->setDefaultArg(Arg);
- }
+ } else if (Expr *Arg = OldParm->getDefaultArg())
+ // FIXME: if we non-lazily instantiated non-dependent default args for
+ // non-dependent parameter types we could remove a bunch of duplicate
+ // conversion warnings for such arguments.
+ NewParm->setUninstantiatedDefaultArg(Arg);
NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg());
Modified: cfe/trunk/test/CodeGenCXX/destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=155893&r1=155892&r2=155893&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Tue May 1 01:05:57 2012
@@ -350,6 +350,22 @@
// CHECK: unreachable
}
+// PR12710
+namespace test9 {
+ struct ArgType {
+ ~ArgType();
+ };
+ template<typename T>
+ void f1(const ArgType& = ArgType());
+ void f2();
+ void bar() {
+ f1<int>();
+ f2();
+ }
+ // CHECK: call void @_ZN5test97ArgTypeD1Ev(%"struct.test9::ArgType"* %ref.tmp)
+ // CHECK: call void @_ZN5test92f2Ev()
+}
+
// Checks from test3:
// CHECK: define internal void @_ZN5test312_GLOBAL__N_11DD0Ev(%"struct.test3::<anonymous namespace>::D"* %this) unnamed_addr
Modified: cfe/trunk/test/SemaCXX/conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion.cpp?rev=155893&r1=155892&r2=155893&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/conversion.cpp Tue May 1 01:05:57 2012
@@ -83,8 +83,10 @@
}
namespace test4 {
+ // FIXME: We should warn for non-dependent args (only when the param type is also non-dependent) only once
+ // not once for the template + once for every instantiation
template<typename T>
- void tmpl(char c = NULL, // expected-warning {{implicit conversion of NULL constant to 'char'}}
+ void tmpl(char c = NULL, // expected-warning 3 {{implicit conversion of NULL constant to 'char'}}
T a = NULL, // expected-warning {{implicit conversion of NULL constant to 'char'}} \
expected-warning {{implicit conversion of NULL constant to 'int'}}
T b = 1024) { // expected-warning {{implicit conversion from 'int' to 'char' changes value from 1024 to 0}}
@@ -95,8 +97,8 @@
}
void func() {
- tmpl<char>(); // expected-note {{in instantiation of default function argument expression for 'tmpl<char>' required here}}
- tmpl<int>(); // expected-note {{in instantiation of default function argument expression for 'tmpl<int>' required here}}
+ tmpl<char>(); // expected-note 2 {{in instantiation of default function argument expression for 'tmpl<char>' required here}}
+ tmpl<int>(); // expected-note 2 {{in instantiation of default function argument expression for 'tmpl<int>' required here}}
tmpl2<int*>();
}
}
More information about the cfe-commits
mailing list