Sema::MergeFunctionDecl attempts merging two decls even if the old decl is invalid. This can lead to interesting circumstances where we successfully merge the decls but the result makes no sense. Take the following for example: template <typename T> int main(void); int main(void); Sema will not consider these to be overloads of the same name because main can't be overloaded, which means that this must be a redeclaration. In this case the templated decl is compatible with the non-templated decl allowing the Sema::CheckFunctionDeclaration machinery to move on and do bizarre things like setting the previous decl of a non-templated decl to a templated decl! The way I see it, we should just bail from MergeFunctionDecl if the old decl is invalid. This fixes PR16531. llvm-svn: 185779
105 lines
1.7 KiB
C++
105 lines
1.7 KiB
C++
// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify -std=c++11 %s
|
|
|
|
template <class T>
|
|
class A {
|
|
void foo() {
|
|
undeclared();
|
|
}
|
|
void foo2();
|
|
};
|
|
|
|
template <class T>
|
|
class B {
|
|
void foo4() { } // expected-note {{previous definition is here}} expected-note {{previous definition is here}}
|
|
void foo4() { } // expected-error {{class member cannot be redeclared}} expected-error {{redefinition of 'foo4'}}
|
|
void foo5() { } // expected-note {{previous definition is here}}
|
|
|
|
friend void foo3() {
|
|
undeclared();
|
|
}
|
|
};
|
|
|
|
|
|
template <class T>
|
|
void B<T>::foo5() { // expected-error {{redefinition of 'foo5'}}
|
|
}
|
|
|
|
template <class T>
|
|
void A<T>::foo2() {
|
|
undeclared();
|
|
}
|
|
|
|
|
|
template <class T>
|
|
void foo3() {
|
|
undeclared();
|
|
}
|
|
|
|
template void A<int>::foo2();
|
|
|
|
|
|
void undeclared()
|
|
{
|
|
|
|
}
|
|
|
|
template <class T> void foo5() {} //expected-note {{previous definition is here}}
|
|
template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}}
|
|
|
|
|
|
|
|
namespace Inner_Outer_same_template_param_name {
|
|
|
|
template <class T>
|
|
class Outmost {
|
|
public:
|
|
template <class T>
|
|
class Inner {
|
|
public:
|
|
void f() {
|
|
T* var;
|
|
}
|
|
};
|
|
};
|
|
|
|
}
|
|
|
|
|
|
namespace PR11931 {
|
|
|
|
template <typename RunType>
|
|
struct BindState;
|
|
|
|
template<>
|
|
struct BindState<void(void*)> {
|
|
static void Run() { }
|
|
};
|
|
|
|
class Callback {
|
|
public:
|
|
typedef void RunType();
|
|
|
|
template <typename RunType>
|
|
Callback(BindState<RunType> bind_state) {
|
|
BindState<RunType>::Run();
|
|
}
|
|
};
|
|
|
|
|
|
Callback Bind() {
|
|
return Callback(BindState<void(void*)>());
|
|
}
|
|
|
|
}
|
|
|
|
namespace rdar11700604 {
|
|
template<typename T> void foo() = delete;
|
|
|
|
struct X {
|
|
X() = default;
|
|
|
|
template<typename T> void foo() = delete;
|
|
};
|
|
}
|
|
|