diff options
author | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-08-29 03:11:50 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-08-29 03:11:50 +0000 |
commit | 8a902edbbdb53a00209e88b6182457941ff196a9 (patch) | |
tree | 076d856b22bc8d9eda1ac6a617c05a42fe929c7e /gcc/cp | |
parent | 737c5bac68732abe28a374658fe85396f92b9ef5 (diff) | |
download | gcc-8a902edbbdb53a00209e88b6182457941ff196a9.zip gcc-8a902edbbdb53a00209e88b6182457941ff196a9.tar.gz gcc-8a902edbbdb53a00209e88b6182457941ff196a9.tar.bz2 |
Implement P1152R4: Deprecating some uses of volatile.
PR c++/91361
* c-opts.c (c_common_post_options): Enable -Wvolatile by
default for C++2a, unless -Wno-deprecated.
* c.opt (Wvolatile): New warning.
* cp-gimplify.c (cp_fold): Set TREE_THIS_VOLATILE.
* decl.c (grokdeclarator): Warn about a volatile-qualified structured
binding and return type.
(grokparms): Warn about a volatile-qualified function parameter.
* expr.c (mark_use) <case MODIFY_EXPR>: Emit a -Wvolatile warning.
* typeck.c (cp_build_unary_op): Emit a -Wvolatile warning for pre and
post ++/-- on a volatile operand.
(genericize_compound_lvalue): Use a better location. Don't lose
TREE_THIS_VOLATILE.
(cp_build_modify_expr): Emit a -Wvolatile warning for a compound
assignment whose LHS is volatile-qualified. Build the assignment with
a more precise location.
* doc/invoke.texi: Document -Wvolatile.
* c-c++-common/Wbool-operation-1.c: Use -Wno-volatile in C++.
* c-c++-common/gomp/atomic-1.c: Likewise.
* c-c++-common/gomp/atomic-9.c: Likewise.
* c-c++-common/gomp/depend-iterator-1.c: Likewise.
* c-c++-common/gomp/loop-1.c: Adjust warning location for C++.
* c-c++-common/gomp/order-3.c: Likewise.
* c-c++-common/pr69733.c: Use -Wno-volatile in C++.
* c-c++-common/spec-barrier-2.c: Likewise.
* c-c++-common/tm/pr54893.c: Likewise.
* g++.dg/cpp0x/pr65327.C: Add dg-warning.
* g++.dg/cpp0x/rv-conv2.C: Likewise.
* g++.dg/cpp0x/rv1n.C: Likewise.
* g++.dg/cpp0x/rv1p.C: Likewise.
* g++.dg/cpp0x/rv2n.C: Likewise.
* g++.dg/cpp0x/rv2p.C: Likewise.
* g++.dg/cpp0x/rv3n.C: Likewise.
* g++.dg/cpp0x/rv3p.C: Likewise.
* g++.dg/cpp0x/rv4n.C: Likewise.
* g++.dg/cpp0x/rv4p.C: Likewise.
* g++.dg/cpp0x/rv5n.C: Likewise.
* g++.dg/cpp0x/rv5p.C: Likewise.
* g++.dg/cpp0x/rv6n.C: Likewise.
* g++.dg/cpp0x/rv6p.C: Likewise.
* g++.dg/cpp0x/rv7n.C: Likewise.
* g++.dg/cpp0x/rv7p.C: Likewise.
* g++.dg/cpp0x/rv8p.C: Likewise.
* g++.dg/cpp0x/trailing14.C: Use -Wno-volatile.
* g++.dg/cpp1y/new1.C: Add dg-warning.
* g++.dg/cpp2a/volatile1.C: New test.
* g++.dg/cpp2a/volatile2.C: New test.
* g++.dg/cpp2a/volatile3.C: New test.
* g++.dg/cpp2a/volatile4.C: New test.
* g++.dg/expr/bool3.C: Add dg-warning.
* g++.dg/expr/bool4.C: Likewise.
* g++.dg/expr/cond9.C: Likewise.
* g++.dg/ext/vector25.C: Likewise.
* g++.dg/gomp/depend-iterator-1.C: Use -Wno-volatile.
* g++.dg/inherit/covariant21.C: Add dg-warning.
* g++.dg/init/ref18.C: Likewise.
* g++.dg/ipa/pr63838.C: Likewise.
* g++.dg/overload/rvalue2.C: Likewise.
* g++.dg/parse/semicolon4.C: Likewise.
* g++.dg/warn/Wreturn-type-4.C: Likewise.
* g++.dg/warn/pr36069.C: Likewise.
* g++.old-deja/g++.mike/p9506.C: Likewise.
* g++.old-deja/g++.other/volatile1.C: Likewise.
From-SVN: r275022
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/cp/cp-gimplify.c | 3 | ||||
-rw-r--r-- | gcc/cp/decl.c | 18 | ||||
-rw-r--r-- | gcc/cp/expr.c | 22 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 24 |
5 files changed, 82 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2e7c26c..818d32b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,22 @@ 2019-08-28 Marek Polacek <polacek@redhat.com> + Implement P1152R4: Deprecating some uses of volatile. + PR c++/91361 + * cp-gimplify.c (cp_fold): Set TREE_THIS_VOLATILE. + * decl.c (grokdeclarator): Warn about a volatile-qualified structured + binding and return type. + (grokparms): Warn about a volatile-qualified function parameter. + * expr.c (mark_use) <case MODIFY_EXPR>: Emit a -Wvolatile warning. + * typeck.c (cp_build_unary_op): Emit a -Wvolatile warning for pre and + post ++/-- on a volatile operand. + (genericize_compound_lvalue): Use a better location. Don't lose + TREE_THIS_VOLATILE. + (cp_build_modify_expr): Emit a -Wvolatile warning for a compound + assignment whose LHS is volatile-qualified. Build the assignment with + a more precise location. + +2019-08-28 Marek Polacek <polacek@redhat.com> + PR c++/91360 - Implement C++20 P1143R2: constinit. * cp-tree.h (TINFO_VAR_DECLARED_CONSTINIT): Define. (LOOKUP_CONSTINIT): Define. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 065dcb7..49fa47a 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -2507,6 +2507,9 @@ cp_fold (tree x) else x = org_x; } + if (code == MODIFY_EXPR && TREE_CODE (x) == MODIFY_EXPR) + TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x); + break; case VEC_COND_EXPR: diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c5cc22a..2aef330 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11233,6 +11233,10 @@ grokdeclarator (const cp_declarator *declarator, if (concept_p) error_at (declspecs->locations[ds_concept], "structured binding declaration cannot be %qs", "concept"); + /* [dcl.struct.bind] "A cv that includes volatile is deprecated." */ + if (type_quals & TYPE_QUAL_VOLATILE) + warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile, + "%<volatile%>-qualified structured binding is deprecated"); switch (storage_class) { case sc_none: @@ -11623,6 +11627,13 @@ grokdeclarator (const cp_declarator *declarator, if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)) warning_at (typespec_loc, OPT_Wignored_qualifiers, "type " "qualifiers ignored on function return type"); + /* [dcl.fct] "A volatile-qualified return type is + deprecated." */ + if (type_quals & TYPE_QUAL_VOLATILE) + warning_at (typespec_loc, OPT_Wvolatile, + "%<volatile%>-qualified return type is " + "deprecated"); + /* We now know that the TYPE_QUALS don't apply to the decl, but to its return type. */ type_quals = TYPE_UNQUALIFIED; @@ -13378,6 +13389,13 @@ grokparms (tree parmlist, tree *parms) cp_warn_deprecated_use (deptype); } + /* [dcl.fct] "A parameter with volatile-qualified type is + deprecated." */ + if (CP_TYPE_VOLATILE_P (type)) + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile, + "%<volatile%>-qualified parameter is " + "deprecated"); + /* Top-level qualifiers on the parameters are ignored for function types. */ type = cp_build_qualified_type (type, 0); diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c index 9160043..212a7f9 100644 --- a/gcc/cp/expr.c +++ b/gcc/cp/expr.c @@ -207,6 +207,28 @@ mark_use (tree expr, bool rvalue_p, bool read_p, recurse_op[0] = true; break; + case MODIFY_EXPR: + { + tree lhs = TREE_OPERAND (expr, 0); + /* [expr.ass] "A simple assignment whose left operand is of + a volatile-qualified type is deprecated unless the assignment + is either a discarded-value expression or appears in an + unevaluated context." */ + if (read_p + && !cp_unevaluated_operand + && (TREE_THIS_VOLATILE (lhs) + || CP_TYPE_VOLATILE_P (TREE_TYPE (lhs))) + && !TREE_THIS_VOLATILE (expr)) + { + warning_at (location_of (expr), OPT_Wvolatile, + "using value of simple assignment with %<volatile%>-" + "qualified left operand is deprecated"); + /* Make sure not to warn about this assignment again. */ + TREE_THIS_VOLATILE (expr) = true; + } + break; + } + default: break; } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c09bb30..d4f2d981 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6459,6 +6459,17 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert, complain)) return error_mark_node; + /* [depr.volatile.type] "Postfix ++ and -- expressions and + prefix ++ and -- expressions of volatile-qualified arithmetic + and pointer types are deprecated." */ + if (TREE_THIS_VOLATILE (arg) || CP_TYPE_VOLATILE_P (TREE_TYPE (arg))) + warning_at (location, OPT_Wvolatile, + "%qs expression of %<volatile%>-qualified type is " + "deprecated", + ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "++" : "--")); + /* Forbid using -- or ++ in C++17 on `bool'. */ if (TREE_CODE (declared_type) == BOOLEAN_TYPE) { @@ -8278,6 +8289,15 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, && MAYBE_CLASS_TYPE_P (TREE_TYPE (lhstype))) || MAYBE_CLASS_TYPE_P (lhstype))); + /* An expression of the form E1 op= E2. [expr.ass] says: + "Such expressions are deprecated if E1 has volatile-qualified + type." We warn here rather than in cp_genericize_r because + for compound assignments we are supposed to warn even if the + assignment is a discarded-value expression. */ + if (TREE_THIS_VOLATILE (lhs) || CP_TYPE_VOLATILE_P (lhstype)) + warning_at (loc, OPT_Wvolatile, + "compound assignment with %<volatile%>-qualified left " + "operand is deprecated"); /* Preevaluate the RHS to make sure its evaluation is complete before the lvalue-to-rvalue conversion of the LHS: @@ -8450,8 +8470,8 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, goto ret; } - result = build2 (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR, - lhstype, lhs, newrhs); + result = build2_loc (loc, modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR, + lhstype, lhs, newrhs); TREE_SIDE_EFFECTS (result) = 1; if (!plain_assign) |