teak-llvm/clang/test/SemaCXX/invalid-template-params.cpp
Akira Hatanaka 12ddceecde [Sema] Fix a crash-on-invalid when a template parameter list has a class
definition or non-reference class type.

The crash occurs when there is a template parameter list in a class that
is missing the closing angle bracket followed by a definition of a
struct. For example:

class C0 {
public:
  template<typename T, typename T1 = T // missing closing angle bracket
  struct S0 {};

  C0() : m(new S0<int>) {}
  S0<int> *m;
};

This happens because the parsed struct is added to the scope of the
enclosing class without having its access specifier set, which results
in an assertion failure in SemaAccess.cpp later.

This commit fixes the crash by adding the parsed struct to the enclosing
file scope and marking structs as invalid if they are defined in
template parameter lists.

rdar://problem/31783961
rdar://problem/19570630

Differential Revision: https://reviews.llvm.org/D33606

llvm-svn: 306317
2017-06-26 18:46:12 +00:00

24 lines
1.3 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
template<class> class Foo {
template<class UBar // expected-error {{expected ';' after class}}
// expected-note@-1 {{'UBar' declared here}}
void foo1(); // expected-error {{a non-type template parameter cannot have type 'class UBar'}}
// expected-error@-1 {{expected ',' or '>' in template-parameter-list}}
// expected-warning@-2 {{declaration does not declare anything}}
};
Foo<int>::UBar g1; // expected-error {{no type named 'UBar' in 'Foo<int>'}}
class C0 {
public:
template<typename T0, typename T1 = T0 // missing closing angle bracket
struct S0 {}; // expected-error {{'S0' cannot be defined in a type specifier}}
// expected-error@-1 {{cannot combine with previous 'type-name' declaration specifier}}
// expected-error@-2 {{expected ',' or '>' in template-parameter-list}}
// expected-warning@-3 {{declaration does not declare anything}}
C0() : m(new S0<int>) {} // expected-error {{expected '(' for function-style cast or type construction}}
// expected-error@-1 {{expected expression}}
S0<int> *m; // expected-error {{expected member name or ';' after declaration specifiers}}
};