From c0da34e6ab12c87304bc753c75fdea7cdb49a947 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 22 Jan 2013 19:32:27 +0000 Subject: [PATCH] Split "discards qualifiers" warnings of -Wincompatible-pointer-types into subgroup. This allows users to promote -Wincompatible-pointer-type warnings to errors but keep those for "discard qualifiers" as warnings (if they so desire). Addresses . llvm-svn: 173184 --- clang/include/clang/Basic/DiagnosticGroups.td | 6 +++++- clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++-- .../test/Sema/incompatible-pointer-types-error.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 clang/test/Sema/incompatible-pointer-types-error.c diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 8a2d59658690..7709be139bbc 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -124,7 +124,11 @@ def DanglingField : DiagGroup<"dangling-field">; def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">; def : DiagGroup<"import">; -def IncompatiblePointerTypes : DiagGroup<"incompatible-pointer-types">; +def IncompatiblePointerTypesDiscardsQualifiers + : DiagGroup<"incompatible-pointer-types-discards-qualifiers">; +def IncompatiblePointerTypes + : DiagGroup<"incompatible-pointer-types", + [IncompatiblePointerTypesDiscardsQualifiers]>; def IncompleteUmbrella : DiagGroup<"incomplete-umbrella">; def InvalidNoreturn : DiagGroup<"invalid-noreturn">; def InvalidSourceEncoding : DiagGroup<"invalid-source-encoding">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 3b37658abba2..053f39207a29 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4902,7 +4902,7 @@ def ext_typecheck_convert_discards_qualifiers : ExtWarn< "sending to parameter of different type}0,1" "|%diff{casting $ to type $|casting between types}0,1}2" " discards qualifiers">, - InGroup; + InGroup; def ext_nested_pointer_qualifier_mismatch : ExtWarn< "%select{%diff{assigning to $ from $|assigning to different types}0,1" "|%diff{passing $ to parameter of type $|" @@ -4916,7 +4916,7 @@ def ext_nested_pointer_qualifier_mismatch : ExtWarn< "sending to parameter of different type}0,1" "|%diff{casting $ to type $|casting between types}0,1}2" " discards qualifiers in nested pointer types">, - InGroup; + InGroup; def warn_incompatible_vectors : Warning< "incompatible vector types " "%select{%diff{assigning to $ from $|assigning to different types}0,1" diff --git a/clang/test/Sema/incompatible-pointer-types-error.c b/clang/test/Sema/incompatible-pointer-types-error.c new file mode 100644 index 000000000000..fda45cf1630b --- /dev/null +++ b/clang/test/Sema/incompatible-pointer-types-error.c @@ -0,0 +1,16 @@ +// RUN: %clang -fsyntax-only %s -Xclang -verify -Werror=incompatible-pointer-types -Wno-error=incompatible-pointer-types-discards-qualifiers + +// This test ensures that the subgroup of -Wincompatible-pointer-types warnings that +// concern discarding qualifers can be promoted (or not promoted) to an error *separately* from +// the other -Wincompatible-pointer-type warnings. +// +// +// + +void foo(char *s); // expected-note {{passing argument to parameter 's' here}} +void baz(int *s); // expected-note {{passing argument to parameter 's' here}} + +void bar(const char *s) { + foo(s); // expected-warning {{passing 'const char *' to parameter of type 'char *' discards qualifiers}} + baz(s); // expected-error {{incompatible pointer types passing 'const char *' to parameter of type 'int *'}} +}