diff options
author | John McCall <rjmccall@apple.com> | 2011-07-06 07:30:07 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-07-06 07:30:07 +0000 |
commit | 542e7c6f64995a9f7a92f19b3e6ceaa95aa28bc5 (patch) | |
tree | 64137898d87f22d785944f4310bd0c114f37af24 | |
parent | 21878760a45cd442084dcba299b34ed79ccaa957 (diff) | |
download | bcm5719-llvm-542e7c6f64995a9f7a92f19b3e6ceaa95aa28bc5.tar.gz bcm5719-llvm-542e7c6f64995a9f7a92f19b3e6ceaa95aa28bc5.zip |
When tree-transforming an expression sequence, always flag expanded
variadic argument pack expansions as having changed, rather than doing
it for each changed expansion, which leaves out zero-argument packs
with catastrophic consequences.
Fixes PR10260.
llvm-svn: 134483
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 12 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/variadic-templates.cpp | 11 |
2 files changed, 18 insertions, 5 deletions
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index edbf1fb4590..66ea7df4ee7 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1547,9 +1547,9 @@ public: /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. ExprResult RebuildInitList(SourceLocation LBraceLoc, - MultiExprArg Inits, - SourceLocation RBraceLoc, - QualType ResultTy) { + MultiExprArg Inits, + SourceLocation RBraceLoc, + QualType ResultTy) { ExprResult Result = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); if (Result.isInvalid() || ResultTy->isDependentType()) @@ -2476,6 +2476,10 @@ bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, Outputs.push_back(Out.get()); continue; } + + // Record right away that the argument was changed. This needs + // to happen even if the array expands to nothing. + if (ArgChanged) *ArgChanged = true; // The transform has determined that we should perform an elementwise // expansion of the pattern. Do so. @@ -2492,8 +2496,6 @@ bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, return true; } - if (ArgChanged) - *ArgChanged = true; Outputs.push_back(Out.get()); } diff --git a/clang/test/CodeGenCXX/variadic-templates.cpp b/clang/test/CodeGenCXX/variadic-templates.cpp index 4f3cf1fe9db..90c83706755 100644 --- a/clang/test/CodeGenCXX/variadic-templates.cpp +++ b/clang/test/CodeGenCXX/variadic-templates.cpp @@ -9,4 +9,15 @@ int get_num_types(Types...) { // CHECK: ret i32 3 template int get_num_types(int, float, double); +// PR10260 - argument packs that expand to nothing +namespace test1 { + template <class... T> void foo() { + int values[sizeof...(T)+1] = { T::value... }; + // CHECK: define linkonce_odr void @_ZN5test13fooIJEEEvv() + // CHECK: alloca [1 x i32], align 4 + } + void test() { + foo<>(); + } +} |