160 lines · cpp
1// RUN: %clang_cc1 %s -std=c++11 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify2// RUN: %clang_cc1 %s -std=c++14 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify3 4int test1() {5 throw;6}7 8// PR50719template<typename T> T f() { }10 11template<typename T>12void g(T t) {13 return t * 2; // okay14}15 16template<typename T>17T h() {18 return 17;19}20 21// Don't warn on cv-qualified class return types, only scalar return types.22namespace ignored_quals {23struct S {};24const S class_c();25const volatile S class_cv();26 27const int scalar_c(); // expected-warning{{'const' type qualifier on return type has no effect}}28int const scalar_c2(); // expected-warning{{'const' type qualifier on return type has no effect}}29 30const31char*32const // expected-warning{{'const' type qualifier on return type has no effect}}33f();34 35char36const*37const // expected-warning{{'const' type qualifier on return type has no effect}}38g();39 40char* const h(); // expected-warning{{'const' type qualifier on return type has no effect}}41char* volatile i(); // expected-warning{{'volatile' type qualifier on return type has no effect}}42 43char*44volatile // expected-warning{{'const volatile' type qualifiers on return type have no effect}}45const46j();47 48const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}49 50// FIXME: Maintain enough information that we can point the diagnostic at the 'volatile' keyword.51const52int S::*53volatile54mixed_ret(); // expected-warning {{'volatile' type qualifier on return type has no effect}}55 56const int volatile // expected-warning {{'const volatile' type qualifiers on return type have no effect}}57 (((parens())));58 59_Atomic(int) atomic();60 61_Atomic // expected-warning {{'_Atomic' type qualifier on return type has no effect}}62 int63 atomic();64 65auto trailing_return_type() ->66 const int; // expected-warning {{'const' type qualifier on return type has no effect}}67 68auto trailing_return_type_lambda = [](const int &x) ->69 const int // expected-warning {{'const' type qualifier on return type has no effect}}70 { return x; };71 72const int ret_array()[4]; // expected-error {{cannot return array}}73}74 75namespace PR9328 {76 typedef char *PCHAR;77 class Test78 {79 const PCHAR GetName() { return 0; } // expected-warning{{'const' type qualifier on return type has no effect}}80 };81}82 83class foo {84 operator const int ();85 operator int * const ();86};87 88namespace PR10057 {89 struct S {90 ~S();91 };92 93 template <class VarType>94 void Test(const VarType& value) {95 return S() = value;96 }97}98 99namespace return_has_expr {100 struct S {101 S() {102 return 42; // expected-error {{constructor 'S' should not return a value}}103 }104 ~S() {105 return 42; // expected-error {{destructor '~S' should not return a value}}106 }107 };108}109 110// pr17759111namespace ctor_returns_void {112 void f() {}113 struct S {114 S() { return f(); } // expected-error {{constructor 'S' must not return void expression}}115 ~S() { return f(); } // expected-error {{destructor '~S' must not return void expression}}116 };117 118 template <typename T> struct ST {119 ST() { return f(); } // expected-error {{constructor 'ST<T>' must not return void expression}}120 // expected-error@-1 {{constructor 'ST' must not return void expression}}121 ~ST() { return f(); } // expected-error {{destructor '~ST<T>' must not return void expression}}122 // expected-error@-1 {{destructor '~ST' must not return void expression}}123 };124 125 ST<int> st; // expected-note {{in instantiation of member function 'ctor_returns_void::ST<int>::ST'}}126 // expected-note@-1 {{in instantiation of member function 'ctor_returns_void::ST<int>::~ST'}}127}128 129void cxx_unresolved_expr() {130 // The use of an undeclared variable tricks clang into building a131 // CXXUnresolvedConstructExpr, and the missing ')' gives it an invalid source132 // location for its rparen. Check that emitting a diag on the range of the133 // expr doesn't assert.134 return int(undeclared, 4; // expected-error {{use of undeclared identifier 'undeclared'}}135}136 137#if __cplusplus >= 201402L138namespace GH43054 {139struct S{};140const auto foo() { return 0; } // expected-warning {{'const' type qualifier on return type has no effect}}141const auto bar() { return S{}; }142template <typename T>143const auto baz() { return T{}; }144 145void test() {146 baz<int>();147 baz<S>();148 149 []() -> const auto { // expected-warning {{'const' type qualifier on return type has no effect}}150 return 0;151 }();152 153 []() -> const auto {154 return S{};155 }();156}157}158 159#endif160