From 32791cc3e1529efe8ac348eafc94910d421683fc Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 6 Jan 2016 22:34:54 +0000 Subject: Only instantiate a default argument once. By storing the instantiated expression back in the ParmVarDecl, we remove the last need for separately storing the sub-expression of a CXXDefaultArgExpr. This makes PCH/Modules merging quite simple: CXXDefaultArgExpr records are serialized as references to the ParmVarDecl, and we ignore redundant attempts to overwrite the instantiated expression. This has some extremely marginal impact on user-facing semantics. However, the major effect is that it avoids IRGen errors about conflicting definitions due to lambdas in the argument being instantiated multiple times while sharing the same mangling. It should also slightly improve memory usage and module file size. rdar://23810407 llvm-svn: 256983 --- clang/test/SemaTemplate/default-arguments-cxx0x.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'clang/test/SemaTemplate/default-arguments-cxx0x.cpp') diff --git a/clang/test/SemaTemplate/default-arguments-cxx0x.cpp b/clang/test/SemaTemplate/default-arguments-cxx0x.cpp index 4cfd7a5843f..0c97c2056b7 100644 --- a/clang/test/SemaTemplate/default-arguments-cxx0x.cpp +++ b/clang/test/SemaTemplate/default-arguments-cxx0x.cpp @@ -56,3 +56,22 @@ namespace PR16975 { baz data{0}; } + +// rdar://23810407 +// An IRGen failure due to a symbol collision due to a default argument +// being instantiated twice. Credit goes to Richard Smith for this +// reduction to a -fsyntax-only failure. +namespace rdar23810407 { + // Instantiating the default argument multiple times will produce two + // different lambda types and thus instantiate this function multiple + // times, which will produce conflicting extern variable declarations. + template int f(T t) { + extern T rdar23810407_variable; + return 0; + } + template int g(int a = f([] {})); + void test() { + g(); + g(); + } +} -- cgit v1.2.3