C++ ObjC++ Var(warn_subobject_linkage) Warning Init(1)
Warn if a class type has a base or a field whose type uses the anonymous namespace or depends on a type with no linkage.
+Welaborated-enum-base
+C++ ObjC++ Var(warn_elaborated_enum_base) Warning Init(1)
+Warn if an additional enum-base is used in an elaborated-type-specifier.
+
Wduplicate-decl-specifier
C ObjC Var(warn_duplicate_decl_specifier) Warning LangEnabledBy(C ObjC,Wall)
Warn when a declaration has duplicate const, volatile, restrict or _Atomic specifier.
/* Check for the `:' that denotes a specified underlying type in C++0x.
Note that a ':' could also indicate a bitfield width, however. */
+ location_t colon_loc = UNKNOWN_LOCATION;
if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
{
cp_decl_specifier_seq type_specifiers;
/* Consume the `:'. */
+ colon_loc = cp_lexer_peek_token (parser->lexer)->location;
cp_lexer_consume_token (parser->lexer);
auto tdf
&& cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
{
if (has_underlying_type)
- cp_parser_commit_to_tentative_parse (parser);
- cp_parser_error (parser, "expected %<;%> or %<{%>");
- if (has_underlying_type)
- return error_mark_node;
+ pedwarn (colon_loc,
+ OPT_Welaborated_enum_base,
+ "declaration of enumeration with "
+ "fixed underlying type and no enumerator list is "
+ "only permitted as a standalone declaration");
+ else
+ cp_parser_error (parser, "expected %<;%> or %<{%>");
}
}
-Wdelete-non-virtual-dtor -Wno-deprecated-array-compare
-Wdeprecated-copy -Wdeprecated-copy-dtor
-Wno-deprecated-enum-enum-conversion -Wno-deprecated-enum-float-conversion
--Weffc++ -Wno-exceptions -Wextra-semi -Wno-inaccessible-base
+-Weffc++ -Wno-elaborated-enum-base
+-Wno-exceptions -Wextra-semi -Wno-inaccessible-base
-Wno-inherited-variadic-ctor -Wno-init-list-lifetime
-Winvalid-constexpr -Winvalid-imported-macros
-Wno-invalid-offsetof -Wno-literal-suffix
@option{-std=c++20}. In pre-C++20 dialects, this warning can be enabled
by @option{-Wenum-conversion}.
+@opindex Welaborated-enum-base
+@opindex Wno-elaborated-enum-base
+@item -Wno-elaborated-enum-base
+For C++11 and above, warn if an (invalid) additional enum-base is used
+in an elaborated-type-specifier. That is, if an enum with given
+underlying type and no enumerator list is used in a declaration other
+than just a standalone declaration of the enum. Enabled by default. This
+warning is upgraded to an error with -pedantic-errors.
+
@opindex Winit-list-lifetime
@opindex Wno-init-list-lifetime
@item -Wno-init-list-lifetime @r{(C++ and Objective-C++ only)}
-Wchanges-meaning @r{(C++)}
-Wcomma-subscript @r{(C++23 or later)}
-Wdeclaration-after-statement @r{(C90 or earlier)}
+-Welaborated-enum-base @r{(C++11 or later)}
-Wimplicit-int @r{(C99 or later)}
-Wimplicit-function-declaration @r{(C99 or later)}
-Wincompatible-pointer-types
--- /dev/null
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+// Empty dg-options to override -pedantic-errors.
+
+typedef long CFIndex;
+typedef enum CFComparisonResult : CFIndex CFComparisonResult;
+// { dg-warning "declaration of enumeration with fixed underlying type" "" { target *-*-* } .-1 }
void
foo ()
{
- enum : int a alignas; // { dg-error "expected" }
+ enum : int a alignas; // { dg-error "declaration of enum" }
+ // { dg-error {expected '\(' before ';'} "" { target *-*-* } .-1 }
}
void
bar ()
{
- enum : int a; // { dg-error "expected" }
+ enum : int a; // { dg-error "declaration of enum" }
}
void
baz ()
{
- enum class a : int b alignas; // { dg-error "expected" }
+ enum class a : int b alignas; // { dg-error "declaration of enum" }
+ // { dg-error {expected '\(' before ';'} "" { target *-*-* } .-1 }
}
void
qux ()
{
- enum class a : int b; // { dg-error "expected" }
+ enum class a : int b; // { dg-error "declaration of enum" }
}
enum class E3 e3; // { dg-error "scoped enum must not use" }
enum struct E3 e4; // { dg-error "scoped enum must not use" }
-enum E5 : int e5; // { dg-error "expected|invalid type" }
+enum E5 : int e5; // { dg-error "declaration of enumeration with fixed underlying type|invalid type" }
enum E6 : int { a, b, c }; // { dg-message "previous definition" }
enum E6 : int { a, b, c }; // { dg-error "multiple definition" }