teak-llvm/clang/test/CodeGenCXX/mangle-local-class-names.cpp
David Majnemer 766e259e38 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
2013-10-22 04:14:18 +00:00

88 lines
1.3 KiB
C++

// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
// CHECK: @_ZZ4FUNCvEN4SSSSC1ERKf
// CHECK: @_ZZ4FUNCvEN4SSSSC2E_0RKf
// CHECK: @_ZZ4GORFfEN4SSSSC1ERKf
// CHECK: @_ZZ4GORFfEN4SSSSC2E_0RKf
void FUNC ()
{
{
float IVAR1 ;
struct SSSS
{
float bv;
SSSS( const float& from): bv(from) { }
};
SSSS VAR1(IVAR1);
}
{
float IVAR2 ;
struct SSSS
{
SSSS( const float& from) {}
};
SSSS VAR2(IVAR2);
}
}
void GORF (float IVAR1)
{
{
struct SSSS
{
float bv;
SSSS( const float& from): bv(from) { }
};
SSSS VAR1(IVAR1);
}
{
float IVAR2 ;
struct SSSS
{
SSSS( const float& from) {}
};
SSSS VAR2(IVAR2);
}
}
// CHECK: @_ZZ12OmittingCodefEN4SSSSC1E_0RKf
inline void OmittingCode(float x) {
if (0) {
struct SSSS {
float bv;
SSSS(const float& from): bv(from) { }
};
SSSS VAR1(x);
}
struct SSSS {
float bv;
SSSS(const float& from): bv(from) { }
};
SSSS VAR2(x);
}
void CallOmittingCode() { OmittingCode(1); }
// CHECK: @_ZZ15LocalAnonStructvENUt0_1gEv
inline void LocalAnonStruct() {
if (0) {
struct { void f() {} } x;
x.f();
}
struct { void g() {} } y;
y.g();
}
void CallLocalAnonStruct() { LocalAnonStruct(); }