diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-10-22 04:14:18 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-10-22 04:14:18 +0000 |
commit | 766e259e38e51c3773fcbd429f1faef52cb1de36 (patch) | |
tree | 7c5844a7d5fe19fceb13cb47331b2eef11cdeeb2 /clang/test/PCH/cxx-local-templates.cpp | |
parent | a93033cc89648a8df95493ca6a1cee4f257ed312 (diff) | |
download | bcm5719-llvm-766e259e38e51c3773fcbd429f1faef52cb1de36.tar.gz bcm5719-llvm-766e259e38e51c3773fcbd429f1faef52cb1de36.zip |
Sema: Do not allow template declarations inside local classes
Summary:
Enforce the rule in C++11 [temp.mem]p2 that local classes cannot have
member templates.
This fixes PR16947.
N.B. C++14 has slightly different wording to afford generic lambdas
declared inside of functions.
Fun fact: Some formulations of local classes with member templates
would cause clang to crash during Itanium mangling, such as the
following:
void outer_mem() {
struct Inner {
template <typename = void>
struct InnerTemplateClass {
static void itc_mem() {}
};
};
Inner::InnerTemplateClass<>::itc_mem();
}
Reviewers: eli.friedman, rsmith, doug.gregor, faisalv
Reviewed By: doug.gregor
CC: cfe-commits, ygao
Differential Revision: http://llvm-reviews.chandlerc.com/D1866
llvm-svn: 193144
Diffstat (limited to 'clang/test/PCH/cxx-local-templates.cpp')
-rw-r--r-- | clang/test/PCH/cxx-local-templates.cpp | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/clang/test/PCH/cxx-local-templates.cpp b/clang/test/PCH/cxx-local-templates.cpp deleted file mode 100644 index 277ad831099..00000000000 --- a/clang/test/PCH/cxx-local-templates.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t-cxx11
-// RUN: %clang_cc1 -ast-print -pedantic-errors -std=c++11 -include-pch %t-cxx11 %s | FileCheck -check-prefix=CHECK-PRINT %s
-
-#ifndef HEADER_INCLUDED
-
-#define HEADER_INCLUDED
-
-int nontemplate_test(double d) {
- struct Local {
- template<class T> T foo(T t) {
- return t;
- }
- };
- return Local{}.foo(d);
-}
-
-template<class U>
-U template_test(U d) {
- struct Local {
- template<class T> T foo(T t) {
- return t;
- }
- };
- return Local{}.foo(d);
-}
-
-int nested_local() {
- struct Inner1 {
- int inner1_foo(char c) {
- struct Inner2 {
- template<class T> T inner2_foo(T t) {
- return t;
- }
- };
- return Inner2{}.inner2_foo(3.14);
- }
- };
- return Inner1{}.inner1_foo('a');
-}
-
-#else
-
-// CHECK-PRINT: U template_test
-
-// CHECK-PRINT: int nontemplate_test(double)
-
-int nontemplate_test(double);
-
-template double template_test(double);
-int test2(int y) {
- return nontemplate_test(y) + template_test(y);
-}
-
-
-#endif
|