Wire up '-Wignored-qualifiers' to the warning on 'const' in 'const int f()'.

This flag and warning match GCC semantics. Also, move it to -Wextra as this is
a largely cosmetic issue and doesn't seem to mask problems. Subsequent fixes to
the tests which no longer by default emit the warning. Added explicit test
cases for both C and C++ behavior with the warning turned on.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108325 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth 2010-07-14 06:36:18 +00:00
Родитель 773eb03d8c
Коммит 5495f37302
11 изменённых файлов: 29 добавлений и 15 удалений

Просмотреть файл

@ -48,6 +48,7 @@ def CXXHexFloats : DiagGroup<"c++-hex-floats">;
def : DiagGroup<"c++0x-compat", [CXXHexFloats]>;
def FourByteMultiChar : DiagGroup<"four-char-constants">;
def : DiagGroup<"idiomatic-parentheses">;
def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">;
def : DiagGroup<"import">;
def : DiagGroup<"init-self">;
def : DiagGroup<"inline">;
@ -167,6 +168,7 @@ def Format2 : DiagGroup<"format=2",
def Extra : DiagGroup<"extra", [
MissingFieldInitializers,
IgnoredQualifiers,
InitializerOverrides,
SemiBeforeMethodBody,
SignCompare,

Просмотреть файл

@ -121,7 +121,8 @@ def warn_use_out_of_scope_declaration : Warning<
def err_inline_non_function : Error<
"'inline' can only appear on functions">;
def warn_qual_return_type : Warning<
"'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">;
"'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
InGroup<IgnoredQualifiers>, DefaultIgnore;
def warn_decl_shadow :
Warning<"declaration shadows a %select{"

Просмотреть файл

@ -13,10 +13,9 @@ int main() {
int (^IFP) () = PFR; // OK
const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}} \
// expected-warning{{type qualifier on return type has no effect}}
const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}}
const int (^CICC) () = CIC; // expected-warning{{type qualifier on return type has no effect}}
const int (^CICC) () = CIC;
int * const (^IPCC) () = 0;

Просмотреть файл

@ -109,10 +109,9 @@ void foo6() {
void foo7()
{
const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' with an expression of type 'int (^)(void)'}} \
// expected-warning{{type qualifier on return type has no effect}}
const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' with an expression of type 'int (^)(void)'}}
const int (^CC) (void) = ^const int{ const int i = 1; return i; }; // expected-warning{{type qualifier on return type has no effect}}
const int (^CC) (void) = ^const int{ const int i = 1; return i; };
int i;

Просмотреть файл

@ -1,4 +1,4 @@
// RUN: %clang %s -fsyntax-only -Wreturn-type -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value
// RUN: %clang %s -fsyntax-only -Wignored-qualifiers -Wreturn-type -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value
// clang emits the following warning by default.
// With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the
@ -239,3 +239,6 @@ int test_static_inline(int x) {
}
static inline int si_forward() {} // expected-warning{{control reaches end of non-void function}}
// Test warnings on ignored qualifiers on return types.
const int ignored_c_quals(); // expected-warning{{'const' type qualifier on return type has no effect}}
const volatile int ignored_cv_quals(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}

Просмотреть файл

@ -5,7 +5,7 @@ struct S {
int two;
};
struct S const foo(void); // expected-warning{{type qualifier on return type has no effect}}
struct S const foo(void);
struct S tmp;

Просмотреть файл

@ -17,7 +17,7 @@ namespace test0 {
void func(const char ci, const B b); // expected-note {{candidate function}}
void func(const B b, const int ci); // expected-note {{candidate function}}
const int Test1() { // expected-warning{{type qualifier on return type has no effect}}
const int Test1() {
func(b1, f()); // expected-error {{call to 'func' is ambiguous}}
return f(); // expected-error {{conversion from 'test0::B' to 'int const' is ambiguous}}

Просмотреть файл

@ -288,11 +288,11 @@ namespace PR7598 {
v = 1,
};
const Enum g() { // expected-warning{{type qualifier on return type has no effect}}
const Enum g() {
return v;
}
const volatile Enum g2() { // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
const volatile Enum g2() {
return v;
}

Просмотреть файл

@ -44,7 +44,7 @@ namespace test2 {
// PR5134
namespace test3 {
class Foo {
friend const int getInt(int inInt = 0); // expected-warning{{'const' type qualifier on return type has no effect}}
friend const int getInt(int inInt = 0);
};
}

Просмотреть файл

@ -1,4 +1,4 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify
// RUN: %clang_cc1 %s -fsyntax-only -Wignored-qualifiers -verify
int test1() {
throw;
@ -16,3 +16,13 @@ template<typename T>
T h() {
return 17;
}
// Don't warn on cv-qualified class return types, only scalar return types.
namespace ignored_quals {
struct S {};
const S class_c();
const volatile S class_cv();
const int scalar_c(); // expected-warning{{'const' type qualifier on return type has no effect}}
const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
}

Просмотреть файл

@ -101,7 +101,7 @@ namespace PR6257 {
// PR7463
namespace PR7463 {
const int f (); // expected-warning{{type qualifier on return type has no effect}}
const int f ();
template <typename T_> void g (T_&); // expected-note{{T_ = int}}
void h (void) { g(f()); } // expected-error{{no matching function for call}}
}