summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2010-07-14 06:36:18 +0000
committerChandler Carruth <chandlerc@gmail.com>2010-07-14 06:36:18 +0000
commitcb3b5a483fde37bce8086fc074f822962c58d952 (patch)
tree0448841834bd2ac0791acd144ffae63b05c5f384
parentbad47f62f6e104687943389d2b151f1a1a2db35b (diff)
downloadbcm5719-llvm-cb3b5a483fde37bce8086fc074f822962c58d952.tar.gz
bcm5719-llvm-cb3b5a483fde37bce8086fc074f822962c58d952.zip
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. llvm-svn: 108325
-rw-r--r--clang/include/clang/Basic/DiagnosticGroups.td2
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/test/Sema/block-call.c5
-rw-r--r--clang/test/Sema/block-return.c5
-rw-r--r--clang/test/Sema/return.c5
-rw-r--r--clang/test/Sema/struct-cast.c2
-rw-r--r--clang/test/SemaCXX/ambig-user-defined-conversions.cpp2
-rw-r--r--clang/test/SemaCXX/conditional-expr.cpp4
-rw-r--r--clang/test/SemaCXX/friend.cpp2
-rw-r--r--clang/test/SemaCXX/return.cpp12
-rw-r--r--clang/test/SemaTemplate/deduction.cpp2
11 files changed, 29 insertions, 15 deletions
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 930fe422cff..49077513c13 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -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,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f6542afa079..01a37fb6f2c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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{"
diff --git a/clang/test/Sema/block-call.c b/clang/test/Sema/block-call.c
index 28e6c68a800..27e4cfc6d46 100644
--- a/clang/test/Sema/block-call.c
+++ b/clang/test/Sema/block-call.c
@@ -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;
diff --git a/clang/test/Sema/block-return.c b/clang/test/Sema/block-return.c
index 33fd183be06..5a4ec010d3a 100644
--- a/clang/test/Sema/block-return.c
+++ b/clang/test/Sema/block-return.c
@@ -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;
diff --git a/clang/test/Sema/return.c b/clang/test/Sema/return.c
index 2d23e080396..54c340634d3 100644
--- a/clang/test/Sema/return.c
+++ b/clang/test/Sema/return.c
@@ -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}}
diff --git a/clang/test/Sema/struct-cast.c b/clang/test/Sema/struct-cast.c
index 3456665a8c5..30ef89242af 100644
--- a/clang/test/Sema/struct-cast.c
+++ b/clang/test/Sema/struct-cast.c
@@ -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;
diff --git a/clang/test/SemaCXX/ambig-user-defined-conversions.cpp b/clang/test/SemaCXX/ambig-user-defined-conversions.cpp
index 9811859fccc..fdb399b03a2 100644
--- a/clang/test/SemaCXX/ambig-user-defined-conversions.cpp
+++ b/clang/test/SemaCXX/ambig-user-defined-conversions.cpp
@@ -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}}
diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp
index f37ccc8a15d..065179b6da5 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -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;
}
diff --git a/clang/test/SemaCXX/friend.cpp b/clang/test/SemaCXX/friend.cpp
index 65e0da761cf..30abcbbeaa5 100644
--- a/clang/test/SemaCXX/friend.cpp
+++ b/clang/test/SemaCXX/friend.cpp
@@ -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);
};
}
diff --git a/clang/test/SemaCXX/return.cpp b/clang/test/SemaCXX/return.cpp
index e682fdfb500..6bdbe52727b 100644
--- a/clang/test/SemaCXX/return.cpp
+++ b/clang/test/SemaCXX/return.cpp
@@ -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}}
+}
diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp
index 25ffb67492a..e8ff8d3a6d2 100644
--- a/clang/test/SemaTemplate/deduction.cpp
+++ b/clang/test/SemaTemplate/deduction.cpp
@@ -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}}
}
OpenPOWER on IntegriCloud