diff options
author | Martin Liska <mliska@suse.cz> | 2022-10-28 10:02:34 +0200 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2022-10-28 10:02:34 +0200 |
commit | 1eb021edb27e26f95cda63df121f6bc951647599 (patch) | |
tree | 7f132fded85bd7d05d81cd4c1227da2fd0c3c2d5 /gcc/c-family | |
parent | 62e475bad0d668c432bb97113cbf73fa281b8b55 (diff) | |
parent | 0607307768b66a90e27c5bc91a247acc938f070e (diff) | |
download | gcc-1eb021edb27e26f95cda63df121f6bc951647599.zip gcc-1eb021edb27e26f95cda63df121f6bc951647599.tar.gz gcc-1eb021edb27e26f95cda63df121f6bc951647599.tar.bz2 |
Merge branch 'master' into devel/sphinx
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 24 | ||||
-rw-r--r-- | gcc/c-family/c-warn.cc | 3 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 4 |
4 files changed, 35 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index bb85e78..ee7b511 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2022-10-26 Marek Polacek <polacek@redhat.com> + + PR c++/106393 + * c.opt (Wdangling-reference): New. + 2022-10-19 Joseph Myers <joseph@codesourcery.com> * c-format.h (enum format_lengths): Add FMT_LEN_w8, FMT_LEN_w16, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 62ab4ba..f9d0d29 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1004,6 +1004,30 @@ extern void c_parse_final_cleanups (void); /* True iff TYPE is cv decltype(nullptr). */ #define NULLPTR_TYPE_P(TYPE) (TREE_CODE (TYPE) == NULLPTR_TYPE) +/* Returns the underlying type of the given enumeration type. The + underlying type is determined in different ways, depending on the + properties of the enum: + + - In C++0x or C2x, the underlying type can be explicitly specified, e.g., + + enum E1 : char { ... } // underlying type is char + + - In a C++0x scoped enumeration, the underlying type is int + unless otherwises specified: + + enum class E2 { ... } // underlying type is int + + - Otherwise, the underlying type is determined based on the + values of the enumerators. In this case, the + ENUM_UNDERLYING_TYPE will not be set until after the definition + of the enumeration is completed by finish_enum. */ +#define ENUM_UNDERLYING_TYPE(TYPE) \ + TREE_TYPE (ENUMERAL_TYPE_CHECK (TYPE)) + +/* Determines whether an ENUMERAL_TYPE has an explicit + underlying type. */ +#define ENUM_FIXED_UNDERLYING_TYPE_P(NODE) (TYPE_LANG_FLAG_5 (NODE)) + extern tree do_case (location_t, tree, tree, tree); extern tree build_stmt (location_t, enum tree_code, ...); extern tree build_real_imag_expr (location_t, enum tree_code, tree); diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index 6742f44..cd59c3c 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -1415,7 +1415,8 @@ warnings_for_convert_and_check (location_t loc, tree type, tree expr, if (TREE_CODE (expr) == INTEGER_CST && (TREE_CODE (type) == INTEGER_TYPE - || TREE_CODE (type) == ENUMERAL_TYPE) + || (TREE_CODE (type) == ENUMERAL_TYPE + && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) != BOOLEAN_TYPE)) && !int_fits_type_p (expr, type)) { /* Do not diagnose overflow in a constant expression merely diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 01d4807..070f85c 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -555,6 +555,10 @@ Wdangling-pointer= C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_dangling_pointer) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 2, 0) IntegerRange(0, 2) Warn for uses of pointers to auto variables whose lifetime has ended. +Wdangling-reference +C++ ObjC++ Var(warn_dangling_reference) Warning LangEnabledBy(C++ ObjC++, Wall) +Warn when a reference is bound to a temporary whose lifetime has ended. + Wdate-time C ObjC C++ ObjC++ CPP(warn_date_time) CppReason(CPP_W_DATE_TIME) Var(cpp_warn_date_time) Init(0) Warning Warn about __TIME__, __DATE__ and __TIMESTAMP__ usage. |