forked from OSchip/llvm-project
[clang][NFC] Tests showing the problems with some uses of NamedDecl::getDeclName in diagnostics, SemaOverload.cpp+SemaStmt.cpp part
This commit is contained in:
parent
be8e5fee91
commit
acf3bdc283
|
@ -7,6 +7,12 @@ void a2 [[noreturn]] () {
|
|||
return; // expected-warning {{function 'a2' declared 'noreturn' should not return}}
|
||||
}
|
||||
|
||||
template <typename T> void a3 [[noreturn]] () {}
|
||||
template <> void a3<int> () { return; } // expected-warning {{function 'a3' declared 'noreturn' should not return}}
|
||||
|
||||
template <typename T> void a4 [[noreturn]] () { return; } // expected-warning 2{{function 'a4' declared 'noreturn' should not return}}
|
||||
void a4_test() { a4<long>(); } // expected-note {{in instantiation of function template specialization 'a4<long>' requested here}}
|
||||
|
||||
[[noreturn, noreturn]] void b() { throw 0; } // expected-error {{attribute 'noreturn' cannot appear multiple times in an attribute specifier}}
|
||||
[[noreturn]] [[noreturn]] void b2() { throw 0; } // ok
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// RUN: %clang_cc1 -Wreturn-type -std=c99 -fsyntax-only -verify=c99 %s
|
||||
// RUN: %clang_cc1 -Wreturn-type -std=c90 -fsyntax-only -verify=c90 %s
|
||||
|
||||
int foo(void) { return; } // c99-error {{non-void function 'foo' should return a value}}
|
||||
// c90-error@-1 {{non-void function 'foo' should return a value}}
|
|
@ -2167,6 +2167,11 @@ namespace PR21786 {
|
|||
namespace PR21859 {
|
||||
constexpr int Fun() { return; } // expected-error {{non-void constexpr function 'Fun' should return a value}}
|
||||
constexpr int Var = Fun();
|
||||
|
||||
template <typename T> constexpr int FunT1() { return; } // expected-error {{non-void constexpr function 'FunT1' should return a value}}
|
||||
template <typename T> constexpr int FunT2() { return 0; }
|
||||
template <> constexpr int FunT2<double>() { return 0; }
|
||||
template <> constexpr int FunT2<int>() { return; } // expected-error {{non-void constexpr function 'FunT2' should return a value}}
|
||||
}
|
||||
|
||||
struct InvalidRedef {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
|
||||
|
||||
consteval int Fun() { return; } // expected-error {{non-void constexpr function 'Fun' should return a value}}
|
||||
|
||||
// FIXME: The diagnostic is wrong; should be "consteval".
|
||||
|
||||
template <typename T> consteval int FunT1() { return; } // expected-error {{non-void constexpr function 'FunT1' should return a value}}
|
||||
template <typename T> consteval int FunT2() { return 0; }
|
||||
template <> consteval int FunT2<double>() { return 0; }
|
||||
template <> consteval int FunT2<int>() { return; } // expected-error {{non-void constexpr function 'FunT2' should return a value}}
|
|
@ -0,0 +1,26 @@
|
|||
// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify
|
||||
|
||||
void f1() { return {1,2}; } // expected-error {{void function 'f1' must not return a value}}
|
||||
|
||||
template <typename T> void f2() { return {1,2}; } // expected-error {{void function 'f2' must not return a value}}
|
||||
|
||||
template <> void f2<float>() { return {1,2}; } // expected-error {{void function 'f2' must not return a value}}
|
||||
|
||||
void test_f2() {
|
||||
f2<int>();
|
||||
f2<float>();
|
||||
}
|
||||
|
||||
struct S {
|
||||
void f3() { return {1,2}; } // expected-error {{void function 'f3' must not return a value}}
|
||||
S() { return {1,2}; } // expected-error {{constructor 'S' must not return a value}}
|
||||
~S() { return {1,2}; } // expected-error {{destructor '~S' must not return a value}}
|
||||
};
|
||||
|
||||
template <typename T> struct ST {
|
||||
void f4() { return {1,2}; } // expected-error {{void function 'f4' must not return a value}}
|
||||
ST() { return {1,2}; } // expected-error {{constructor 'ST<T>' must not return a value}}
|
||||
~ST() { return {1,2}; } // expected-error {{destructor '~ST<T>' must not return a value}}
|
||||
};
|
||||
|
||||
ST<int> st;
|
|
@ -108,9 +108,19 @@ namespace return_has_expr {
|
|||
namespace ctor_returns_void {
|
||||
void f() {}
|
||||
struct S {
|
||||
S() { return f(); }; // expected-error {{constructor 'S' must not return void expression}}
|
||||
S() { return f(); } // expected-error {{constructor 'S' must not return void expression}}
|
||||
~S() { return f(); } // expected-error {{destructor '~S' must not return void expression}}
|
||||
};
|
||||
|
||||
template <typename T> struct ST {
|
||||
ST() { return f(); } // expected-error {{constructor 'ST<T>' must not return void expression}}
|
||||
// expected-error@-1 {{constructor 'ST' must not return void expression}}
|
||||
~ST() { return f(); } // expected-error {{destructor '~ST<T>' must not return void expression}}
|
||||
// expected-error@-1 {{destructor '~ST' must not return void expression}}
|
||||
};
|
||||
|
||||
ST<int> st; // expected-note {{in instantiation of member function 'ctor_returns_void::ST<int>::ST'}}
|
||||
// expected-note@-1 {{in instantiation of member function 'ctor_returns_void::ST<int>::~ST'}}
|
||||
}
|
||||
|
||||
void cxx_unresolved_expr() {
|
||||
|
|
|
@ -20,3 +20,35 @@ struct C {
|
|||
C::f();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct TA {
|
||||
TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'TA'}}
|
||||
~TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the destructor of 'TA'}}
|
||||
|
||||
virtual void f() = 0; // expected-note 2{{'f' declared here}}
|
||||
};
|
||||
|
||||
template <> struct TA<int> {
|
||||
TA() { f(); }
|
||||
~TA() { f(); }
|
||||
void f();
|
||||
};
|
||||
|
||||
template <> struct TA<long> {
|
||||
TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'TA'}}
|
||||
~TA() { f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the destructor of 'TA'}}
|
||||
virtual void f() = 0; // expected-note 2{{'f' declared here}}
|
||||
};
|
||||
|
||||
struct TB : TA<float> { // expected-note {{in instantiation of member function 'TA<float>::TA' requested here}}
|
||||
void f() override; // expected-note@-1 {{in instantiation of member function 'TA<float>::~TA' requested here}}
|
||||
};
|
||||
TB tb;
|
||||
|
||||
struct TC : TA<int> {}; // ok
|
||||
TC tc; // ok
|
||||
|
||||
struct TD : TA<long> {
|
||||
void f() override;
|
||||
};
|
||||
TD td;
|
||||
|
|
|
@ -6,3 +6,15 @@ struct A {
|
|||
A::f(); // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'A'}} // expected-note {{qualified call to 'A'::'f' is treated as a virtual call to 'f' due to -fapple-kext}}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct TA {
|
||||
virtual void f() = 0; // expected-note {{'f' declared here}}
|
||||
|
||||
TA() { TA::f(); } // expected-warning {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'TA'}} // expected-note {{qualified call to 'TA'::'f' is treated as a virtual call to 'f' due to -fapple-kext}}
|
||||
};
|
||||
|
||||
struct B : TA<int> { // expected-note {{in instantiation of member function 'TA<int>::TA' requested here}}
|
||||
void f() override;
|
||||
};
|
||||
|
||||
B b;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s
|
||||
|
||||
@interface Test
|
||||
- (int)foo;
|
||||
@end
|
||||
|
||||
@implementation Test
|
||||
- (int)foo { return; } // expected-error {{non-void method 'foo' should return a value}}
|
||||
@end
|
Loading…
Reference in New Issue