Commit ce529ffc by Matthew Beliveau Committed by Matthew Beliveau

re PR c++/90590 (enumeration value not handled in switch warning for std::ios_base::seek_dir)

PR c++/90590

	* c-warn.c (c_do_switch_warnings): Suppress warning for enumerators
	with reserved names that are in a system header.

	* c-c++-common/pr90590-1.c: New test.
	* c-c++-common/pr90590-1.h: New test.
	* c-c++-common/pr90590-2.c: New test.
	* c-c++-common/pr90590-2.h: New test.

From-SVN: r273980
parent 2c726f94
2019-08-01 Matthew Beliveau <mbelivea@redhat.com>
PR c++/90590
* c-warn.c (c_do_switch_warnings): Suppress warning for enumerators
with reserved names that are in a system header.
2019-08-01 Uroš Bizjak <ubizjak@gmail.com> 2019-08-01 Uroš Bizjak <ubizjak@gmail.com>
* config/i386/mmx.md (vec_extractv2si_0): Add (r,x) alternative. * config/i386/mmx.md (vec_extractv2si_0): Add (r,x) alternative.
......
...@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see
#include "gcc-rich-location.h" #include "gcc-rich-location.h"
#include "gimplify.h" #include "gimplify.h"
#include "c-family/c-indentation.h" #include "c-family/c-indentation.h"
#include "c-family/c-spellcheck.h"
#include "calls.h" #include "calls.h"
#include "stor-layout.h" #include "stor-layout.h"
...@@ -1628,6 +1629,15 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location, ...@@ -1628,6 +1629,15 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
if (cond && tree_int_cst_compare (cond, value)) if (cond && tree_int_cst_compare (cond, value))
continue; continue;
/* If the enumerator is defined in a system header and uses a reserved
name, then we continue to avoid throwing a warning. */
location_t loc = DECL_SOURCE_LOCATION
(TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type)));
if (in_system_header_at (loc)
&& name_reserved_for_implementation_p
(IDENTIFIER_POINTER (TREE_PURPOSE (chain))))
continue;
/* If there is a default_node, the only relevant option is /* If there is a default_node, the only relevant option is
Wswitch-enum. Otherwise, if both are enabled then we prefer Wswitch-enum. Otherwise, if both are enabled then we prefer
to warn using -Wswitch because -Wswitch is enabled by -Wall to warn using -Wswitch because -Wswitch is enabled by -Wall
......
2019-08-01 Matthew Beliveau <mbelivea@redhat.com>
PR c++/90590
* c-c++-common/pr90590-1.c: New test.
* c-c++-common/pr90590-1.h: New test.
* c-c++-common/pr90590-2.c: New test.
* c-c++-common/pr90590-2.h: New test.
2019-08-01 Marek Polacek <polacek@redhat.com> 2019-08-01 Marek Polacek <polacek@redhat.com>
PR c++/90805 - detect narrowing in case values. PR c++/90805 - detect narrowing in case values.
......
// PR c++/90590
// { dg-options -Wswitch }
#include "pr90590-1.h"
void
g ()
{
enum E e = _A;
switch (e) // { dg-bogus "enumeration value '_C' not handled in switch" }
{
case _A:
case _B:
break;
}
}
#pragma GCC system_header
enum E { _A, _B, _C };
// PR c++/90590
// { dg-options -Wswitch }
#include "pr90590-2.h"
void
fn ()
{
switch (c.b) // { dg-bogus "enumeration value" }
;
}
#pragma GCC system_header
struct {
enum { _A } b;
} c;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment