+2019-08-28 Marek Polacek <polacek@redhat.com>
+
+ Implement P1152R4: Deprecating some uses of volatile.
+ PR c++/91361
+ * doc/invoke.texi: Document -Wvolatile.
+
2019-08-28 Marek Polacek <polacek@redhat.com>
PR c++/91360 - Implement C++20 P1143R2: constinit.
+2019-08-28 Marek Polacek <polacek@redhat.com>
+
+ 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.
+
2019-08-28 Marek Polacek <polacek@redhat.com>
PR c++/91360 - Implement C++20 P1143R2: constinit.
if (!global_options_set.x_warn_comma_subscript)
warn_comma_subscript = (cxx_dialect >= cxx2a && warn_deprecated);
+ /* -Wvolatile is enabled by default in C++20. */
+ if (!global_options_set.x_warn_volatile)
+ warn_volatile = (cxx_dialect >= cxx2a && warn_deprecated);
+
/* Declone C++ 'structors if -Os. */
if (flag_declone_ctor_dtor == -1)
flag_declone_ctor_dtor = optimize_size;
C ObjC C++ LTO ObjC++ Alias(Wvla-larger-than=,18446744073709551615EiB,none) Warning
-Wno-vla-larger-than Disable Wvla-larger-than= warning. Equivalent to Wvla-larger-than=<SIZE_MAX> or larger.
+Wvolatile
+C++ ObjC++ Var(warn_volatile) Warning
+Warn about deprecated uses of volatile qualifier.
+
Wvolatile-register-var
C ObjC C++ ObjC++ Var(warn_volatile_register_var) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn when a register variable is declared volatile.
+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.
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:
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:
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;
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);
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;
}
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)
{
&& 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:
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)
-Wno-non-template-friend -Wold-style-cast @gol
-Woverloaded-virtual -Wno-pmf-conversions @gol
-Wno-class-conversion -Wno-terminate @gol
--Wsign-promo -Wvirtual-inheritance}
+-Wsign-promo -Wvirtual-inheritance -Wvolatile}
@item Objective-C and Objective-C++ Language Options
@xref{Objective-C and Objective-C++ Dialect Options,,Options Controlling
Disable the warning about the case when a conversion function converts an
object to the same type, to a base class of that type, or to void; such
a conversion function will never be called.
+
+@item -Wvolatile @r{(C++ and Objective-C++ only)}
+@opindex Wvolatile
+@opindex Wno-volatile
+Warn about deprecated uses of the volatile qualifier. This includes postfix
+and prefix @code{++} and @code{--} expressions of volatile-qualified types,
+using simple assignments where the left operand is a volatile-qualified
+non-class type for their value, compound assignments where the left operand
+is a volatile-qualified non-class type, volatile-qualified function return
+type, volatile-qualified parameter type, and structured bindings of a
+volatile-qualified type. This usage was deprecated in C++20.
+
+Enabled by default with @option{-std=c++2a}.
@end table
@node Objective-C and Objective-C++ Dialect Options
+2019-08-28 Marek Polacek <polacek@redhat.com>
+
+ Implement P1152R4: Deprecating some uses of volatile.
+ PR c++/91361
+ * 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.
+
2019-08-28 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/91551
- * gfortran.dg/allocated_3.f90
+ * gfortran.dg/allocated_3.f90
2019-08-28 Marek Polacek <polacek@redhat.com>
/* PR c/77490 */
/* { dg-do compile } */
/* { dg-options "-Wall -Wno-psabi" } */
+/* { dg-additional-options "-Wno-volatile" { target c++ } } */
#ifndef __cplusplus
# define bool _Bool
/* { dg-do compile } */
+/* { dg-additional-options "-Wno-volatile" { target c++ } } */
int x;
volatile int y;
/* { dg-do compile } */
/* { dg-options "-fopenmp -fdump-tree-ompexp" } */
+/* { dg-additional-options "-Wno-volatile" { target c++ } } */
/* { dg-require-effective-target cas_int } */
volatile int *bar(void);
+/* { dg-additional-options "-Wno-volatile" { target c++ } } */
+
int arr[64], arr2[64];
struct S { int a[4]; } k;
short arr4[4];
#pragma omp loop order(concurrent) bind(parallel)
for (i = 0; i < 64; i++)
{
- #pragma omp atomic read
- a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" } */
+ #pragma omp atomic read /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" "" { target c++ } } */
+ a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" "" { target c } } */
}
#pragma omp loop order(concurrent) bind(parallel)
for (i = 0; i < 64; i++)
#pragma omp loop
for (i = 0; i < 64; i++)
{
- #pragma omp atomic read
- a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" } */
+ #pragma omp atomic read /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" "" { target c++ } } */
+ a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" "" { target c } } */
}
#pragma omp loop
for (i = 0; i < 64; i++)
#pragma omp loop
for (i = 0; i < 64; i++)
{
- #pragma omp atomic read
- a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" } */
+ #pragma omp atomic read /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" "" { target c++ } } */
+ a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a 'loop' region" "" { target c } } */
}
#pragma omp loop
for (i = 0; i < 64; i++)
#pragma omp simd order(concurrent)
for (i = 0; i < 64; i++)
{
- #pragma omp atomic read
- a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" } */
+ #pragma omp atomic read /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" "" { target c++ } } */
+ a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" "" { target c } } */
}
#pragma omp simd order(concurrent)
for (i = 0; i < 64; i++)
#pragma omp for simd order(concurrent)
for (i = 0; i < 64; i++)
{
- #pragma omp atomic read
- a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" } */
+ #pragma omp atomic read /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" "" { target c++ } } */
+ a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" "" { target c } } */
}
#pragma omp for simd order(concurrent)
for (i = 0; i < 64; i++)
#pragma omp for order(concurrent)
for (i = 0; i < 64; i++)
{
- #pragma omp atomic read
- a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" } */
+ #pragma omp atomic read /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" "" { target c++ } } */
+ a[i] = v; /* { dg-error "OpenMP constructs other than 'parallel', 'loop' or 'simd' may not be nested inside a region with the 'order\\(concurrent\\)' clause" "" { target c } } */
}
#pragma omp for order(concurrent)
for (i = 0; i < 64; i++)
/* { dg-do compile } */
/* { dg-options "-W -fdiagnostics-show-caret" } */
+/* { dg-additional-options "-Wno-volatile" { target c++ } } */
typedef const double cd;
double val;
cd val2() {return val;}
^~
{ dg-end-multiline-output "" } */
-
/* { dg-do run } */
+/* { dg-additional-options "-Wno-volatile" { target c++ } } */
/* Even on targets that don't need the optional failval parameter,
side-effects on the operand should still be calculated. */
/* { dg-do compile } */
/* { dg-options "-fgnu-tm -fdump-ipa-tmipa" } */
+/* { dg-additional-options "-Wno-volatile" { target c++ } } */
/* Test that volatiles are allowed inside relaxed transactions. */
static constexpr volatile int k = 5;
}
-constexpr volatile int
+constexpr volatile int // { dg-warning "deprecated" "" { target c++2a } }
bar ()
{
return i;
// PR c++/89705
// { dg-do compile { target c++11 } }
-struct W { operator const volatile int(); };
+struct W { operator const volatile int(); }; // { dg-warning "deprecated" "" { target c++2a } }
const int& rci = W();
struct X { operator const int(); };
int&& rri = X();
-struct Y { operator volatile int(); };
+struct Y { operator volatile int(); }; // { dg-warning "deprecated" "" { target c++2a } }
int&& rri2 = Y();
-struct Z { operator const volatile int(); };
+struct Z { operator const volatile int(); }; // { dg-warning "deprecated" "" { target c++2a } }
volatile int&& rri3 = Z();
enum E { A };
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 1 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 1 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 2 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 2 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 3 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 3 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 4 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 4 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 5 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 5 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 6 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 6 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 7 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 7 at a time
A source();
const A c_source();
- volatile A v_source();
-const volatile A cv_source();
+ volatile A v_source(); // { dg-warning "deprecated" "" { target c++2a } }
+const volatile A cv_source(); // { dg-warning "deprecated" "" { target c++2a } }
// 8 at a time
// PR c++/65775
// { dg-do compile { target c++11 } }
-// { dg-options "-Wignored-qualifiers" }
+// { dg-options "-Wignored-qualifiers -Wno-volatile" }
using Qi = int const volatile;
Qi q1(); // { dg-warning "1: type qualifiers ignored" }
test_unused() {
volatile double d = 0.0;
double *p = new double ();
- d += 1.0;
+ d += 1.0; // { dg-warning "deprecated" "" { target c++2a } }
delete p;
}
--- /dev/null
+// PR c++/91361 - P1152R4: Deprecating some uses of volatile.
+// { dg-do compile { target c++17 } }
+
+#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
+
+struct S {
+ volatile int a : 4;
+ int b : 2;
+};
+
+struct T {
+ int a : 4;
+ int b : 2;
+};
+
+union U {
+ char c;
+ int i;
+};
+
+struct W {
+ W();
+ W(volatile W&);
+ W& operator=(volatile W&) volatile;
+};
+
+volatile int // { dg-warning ".volatile.-qualified return type is deprecated" "" { target c++2a } }
+fn (volatile int i) // { dg-warning ".volatile.-qualified parameter is deprecated" "" { target c++2a } }
+{
+ volatile int v = 10;
+ int *volatile p = nullptr;
+
+ // Pre/post ++/--.
+ v++; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ ++v; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ v--; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ --v; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ p++; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ ++p; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ p--; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ --p; // { dg-warning "expression of .volatile.-qualified type is deprecated" "" { target c++2a } }
+ return v + i + *p;
+}
+
+void
+fn2 ()
+{
+ volatile int vi = 42;
+ int i = 24;
+
+ // Discarded-value expression ([expr.context]).
+ // The lvalue-to-rvalue conversion is applied here:
+ vi;
+ // ...but not here. Otherwise we'd write to VI and then immediately read it.
+ vi = 42;
+ vi = i;
+ vi = i = 42;
+ i = vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ &(vi = i); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ (vi = 42, 45);
+ (i = vi = 42, 10); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ i = vi; // LHS not volatile.
+ i = (vi = i, 42);
+ static_cast<void>(vi = i);
+ static_cast<void>(i = vi = 42); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ (void)(vi = i);
+ (void)(i = vi = 42); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+
+ // Unevaluated operand.
+ decltype(vi = 42) x = vi;
+ decltype(i = vi = 42) x3 = i;
+
+ // Compound assignments.
+ vi += i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ vi -= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ vi %= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ vi ^= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ vi |= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ vi /= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ vi = vi += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ vi += vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ i *= vi;
+ decltype(vi -= 42) x2 = vi; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+
+ // Structured bindings.
+ int a[] = { 10, 5 };
+ const auto & [cxr, cyr] = a;
+ const volatile auto & [cvxr, cvyr] = a; // { dg-warning ".volatile.-qualified structured binding is deprecated" "" { target c++2a } }
+ volatile auto & [vxr, vyr] = a; // { dg-warning ".volatile.-qualified structured binding is deprecated" "" { target c++2a } }
+}
+
+void
+fn3 ()
+{
+ volatile int i, j, k = 0;
+ i = j = k; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+
+ ACCESS_ONCE(j);
+
+ S s;
+ s.b = 1;
+
+ volatile U u;
+ u.c = 42;
+ i = u.c = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ u.c += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+
+ volatile T t;
+ t.a = 3;
+ j = t.a = 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ t.a += 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+
+ volatile int *src = &i;
+ *src; // No assignment, don't warn.
+}
+
+void
+fn4 ()
+{
+ volatile W vw;
+ W w;
+ // Assignment to objects of a class is defined by the copy/move assignment
+ // operator.
+ vw = w;
+ w = vw;
+}
+
+template<typename T>
+void raccoon ()
+{
+ volatile T t, u;
+ t = 42;
+ u = t = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+ t &= 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++2a } }
+}
+
+void
+fn5 ()
+{
+ raccoon<int>();
+}
--- /dev/null
+// PR c++/91361 - P1152R4: Deprecating some uses of volatile.
+// { dg-do compile { target c++2a } }
+// { dg-options "-Wno-volatile" }
+
+#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
+
+struct S {
+ volatile int a : 4;
+ int b : 2;
+};
+
+struct T {
+ int a : 4;
+ int b : 2;
+};
+
+union U {
+ char c;
+ int i;
+};
+
+struct W {
+ W();
+ W(volatile W&);
+ W& operator=(volatile W&) volatile;
+};
+
+volatile int
+fn (volatile int i)
+{
+ volatile int v = 10;
+ int *volatile p = nullptr;
+
+ // Pre/post ++/--.
+ v++;
+ ++v;
+ v--;
+ --v;
+ p++;
+ ++p;
+ p--;
+ --p;
+ return v + i + *p;
+}
+
+void
+fn2 ()
+{
+ volatile int vi = 42;
+ int i = 24;
+
+ // Discarded-value expression ([expr.context]).
+ // The lvalue-to-rvalue conversion is applied here:
+ vi;
+ // ...but not here. Otherwise we'd write to VI and then immediately read it.
+ vi = 42;
+ vi = i;
+ vi = i = 42;
+ i = vi = 42;
+ &(vi = i);
+ (vi = 42, 45);
+ (i = vi = 42, 10);
+ i = vi; // LHS not volatile.
+ i = (vi = i, 42);
+ static_cast<void>(vi = i);
+ static_cast<void>(i = vi = 42);
+ (void)(vi = i);
+ (void)(i = vi = 42);
+
+ // Unevaluated operand.
+ decltype(vi = 42) x = vi;
+ decltype(i = vi = 42) x3 = i;
+
+ // Compound assignments.
+ vi += i;
+ vi -= i;
+ vi %= i;
+ vi ^= i;
+ vi |= i;
+ vi /= i;
+ vi = vi += 42;
+ vi += vi = 42;
+ i *= vi;
+ decltype(vi -= 42) x2 = vi;
+
+ // Structured bindings.
+ int a[] = { 10, 5 };
+ const auto & [cxr, cyr] = a;
+ const volatile auto & [cvxr, cvyr] = a;
+ volatile auto & [vxr, vyr] = a;
+}
+
+void
+fn3 ()
+{
+ volatile int i, j, k = 0;
+ i = j = k;
+
+ ACCESS_ONCE(j);
+
+ S s;
+ s.b = 1;
+
+ volatile U u;
+ u.c = 42;
+ i = u.c = 42;
+ u.c += 42;
+
+ volatile T t;
+ t.a = 3;
+ j = t.a = 3;
+ t.a += 3;
+
+ volatile int *src = &i;
+ *src; // No assignment, don't warn.
+}
+
+void
+fn4 ()
+{
+ volatile W vw;
+ W w;
+ // Assignment to objects of a class is defined by the copy/move assignment
+ // operator.
+ vw = w;
+ w = vw;
+}
+
+template<typename T>
+void raccoon ()
+{
+ volatile T t, u;
+ t = 42;
+ u = t = 42;
+ t &= 42;
+}
+
+void
+fn5 ()
+{
+ raccoon<int>();
+}
--- /dev/null
+// PR c++/91361 - P1152R4: Deprecating some uses of volatile.
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wvolatile" }
+
+#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
+
+struct S {
+ volatile int a : 4;
+ int b : 2;
+};
+
+struct T {
+ int a : 4;
+ int b : 2;
+};
+
+union U {
+ char c;
+ int i;
+};
+
+struct W {
+ W();
+ W(volatile W&);
+ W& operator=(volatile W&) volatile;
+};
+
+volatile int // { dg-warning ".volatile.-qualified return type is deprecated" }
+fn (volatile int i) // { dg-warning ".volatile.-qualified parameter is deprecated" }
+{
+ volatile int v = 10;
+ int *volatile p = nullptr;
+
+ // Pre/post ++/--.
+ v++; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ ++v; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ v--; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ --v; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ p++; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ ++p; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ p--; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ --p; // { dg-warning "expression of .volatile.-qualified type is deprecated" }
+ return v + i + *p;
+}
+
+void
+fn2 ()
+{
+ volatile int vi = 42;
+ int i = 24;
+
+ // Discarded-value expression ([expr.context]).
+ // The lvalue-to-rvalue conversion is applied here:
+ vi;
+ // ...but not here. Otherwise we'd write to VI and then immediately read it.
+ vi = 42;
+ vi = i;
+ vi = i = 42;
+ i = vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ &(vi = i); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ (vi = 42, 45);
+ (i = vi = 42, 10); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ i = vi; // LHS not volatile.
+ i = (vi = i, 42);
+ static_cast<void>(vi = i);
+ static_cast<void>(i = vi = 42); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ (void)(vi = i);
+ (void)(i = vi = 42); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+
+ // Unevaluated operand.
+ decltype(vi = 42) x = vi;
+ decltype(i = vi = 42) x3 = i;
+
+ // Compound assignments.
+ vi += i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ vi -= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ vi %= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ vi ^= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ vi |= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ vi /= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ vi = vi += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ vi += vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ i *= vi;
+ decltype(vi -= 42) x2 = vi; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+
+ // Structured bindings.
+ int a[] = { 10, 5 };
+ const auto & [cxr, cyr] = a;
+ const volatile auto & [cvxr, cvyr] = a; // { dg-warning ".volatile.-qualified structured binding is deprecated" }
+ volatile auto & [vxr, vyr] = a; // { dg-warning ".volatile.-qualified structured binding is deprecated" }
+}
+
+void
+fn3 ()
+{
+ volatile int i, j, k = 0;
+ i = j = k; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+
+ ACCESS_ONCE(j);
+
+ S s;
+ s.b = 1;
+
+ volatile U u;
+ u.c = 42;
+ i = u.c = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ u.c += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+
+ volatile T t;
+ t.a = 3;
+ j = t.a = 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ t.a += 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+
+ volatile int *src = &i;
+ *src; // No assignment, don't warn.
+}
+
+void
+fn4 ()
+{
+ volatile W vw;
+ W w;
+ // Assignment to objects of a class is defined by the copy/move assignment
+ // operator.
+ vw = w;
+ w = vw;
+}
+
+template<typename T>
+void raccoon ()
+{
+ volatile T t, u;
+ t = 42;
+ u = t = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+ t &= 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" }
+}
+
+void
+fn5 ()
+{
+ raccoon<int>();
+}
--- /dev/null
+// PR c++/91361 - P1152R4: Deprecating some uses of volatile.
+// { dg-do compile { target c++2a } }
+// { dg-options "-Wno-deprecated" }
+
+#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
+
+struct S {
+ volatile int a : 4;
+ int b : 2;
+};
+
+struct T {
+ int a : 4;
+ int b : 2;
+};
+
+union U {
+ char c;
+ int i;
+};
+
+struct W {
+ W();
+ W(volatile W&);
+ W& operator=(volatile W&) volatile;
+};
+
+volatile int
+fn (volatile int i)
+{
+ volatile int v = 10;
+ int *volatile p = nullptr;
+
+ // Pre/post ++/--.
+ v++;
+ ++v;
+ v--;
+ --v;
+ p++;
+ ++p;
+ p--;
+ --p;
+ return v + i + *p;
+}
+
+void
+fn2 ()
+{
+ volatile int vi = 42;
+ int i = 24;
+
+ // Discarded-value expression ([expr.context]).
+ // The lvalue-to-rvalue conversion is applied here:
+ vi;
+ // ...but not here. Otherwise we'd write to VI and then immediately read it.
+ vi = 42;
+ vi = i;
+ vi = i = 42;
+ i = vi = 42;
+ &(vi = i);
+ (vi = 42, 45);
+ (i = vi = 42, 10);
+ i = vi; // LHS not volatile.
+ i = (vi = i, 42);
+ static_cast<void>(vi = i);
+ static_cast<void>(i = vi = 42);
+ (void)(vi = i);
+ (void)(i = vi = 42);
+
+ // Unevaluated operand.
+ decltype(vi = 42) x = vi;
+ decltype(i = vi = 42) x3 = i;
+
+ // Compound assignments.
+ vi += i;
+ vi -= i;
+ vi %= i;
+ vi ^= i;
+ vi |= i;
+ vi /= i;
+ vi = vi += 42;
+ vi += vi = 42;
+ i *= vi;
+ decltype(vi -= 42) x2 = vi;
+
+ // Structured bindings.
+ int a[] = { 10, 5 };
+ const auto & [cxr, cyr] = a;
+ const volatile auto & [cvxr, cvyr] = a;
+ volatile auto & [vxr, vyr] = a;
+}
+
+void
+fn3 ()
+{
+ volatile int i, j, k = 0;
+ i = j = k;
+
+ ACCESS_ONCE(j);
+
+ S s;
+ s.b = 1;
+
+ volatile U u;
+ u.c = 42;
+ i = u.c = 42;
+ u.c += 42;
+
+ volatile T t;
+ t.a = 3;
+ j = t.a = 3;
+ t.a += 3;
+
+ volatile int *src = &i;
+ *src; // No assignment, don't warn.
+}
+
+void
+fn4 ()
+{
+ volatile W vw;
+ W w;
+ // Assignment to objects of a class is defined by the copy/move assignment
+ // operator.
+ vw = w;
+ w = vw;
+}
+
+template<typename T>
+void raccoon ()
+{
+ volatile T t, u;
+ t = 42;
+ u = t = 42;
+ t &= 42;
+}
+
+void
+fn5 ()
+{
+ raccoon<int>();
+}
b++; // { dg-warning "deprecated" "" { target { ! c++17 } } }
// { dg-error "forbidden" "" { target c++17 } .-1 }
+ // { dg-warning ".volatile.-qualified type is deprecated" "" { target c++2a } .-2 }
b++; // { dg-warning "deprecated" "" { target { ! c++17 } } }
// { dg-error "forbidden" "" { target c++17 } .-1 }
+ // { dg-warning ".volatile.-qualified type is deprecated" "" { target c++2a } .-2 }
i = b;
if (i != 1)
abort ();
{
my_bool b = false;
b--; // { dg-error "" }
+ // { dg-warning ".volatile.-qualified type is deprecated" "" { target c++2a } .-1 }
return 0;
}
-
A(int);
};
-void foo(volatile A a) {
+void foo(volatile A a) { // { dg-warning "deprecated" "" { target c++2a } }
1 ? a : 0; // { dg-error "qualifiers|lvalue|no match" }
1 ? 0 : a; // { dg-error "qualifiers|lvalue|no match" }
}
void foo()
{
- i += i;
+ i += i; // { dg-warning "deprecated" "" { target c++2a } }
}
+// { dg-additional-options "-Wno-volatile" }
+
int arr[64], arr2[64];
struct S { int a[4]; } k;
short arr4[4];
struct X
{
- virtual B* foo(volatile int);
+ virtual B* foo(volatile int); // { dg-warning "deprecated" "" { target c++2a } }
};
struct Y : X
{
- virtual C* foo(volatile int);
+ virtual C* foo(volatile int); // { dg-warning "deprecated" "" { target c++2a } }
};
-C* Y::foo(volatile int) { return 0; }
+C* Y::foo(volatile int) { return 0; } // { dg-warning "deprecated" "" { target c++2a } }
// PR c++/49395
-volatile int foo();
+volatile int foo(); // { dg-warning "deprecated" "" { target c++2a } }
struct A { volatile int i; };
typedef volatile int vi;
__attribute__((noinline, noclone)) static void bar (int);
volatile int v;
void (*fn) ();
-struct S { S () { v++; } ~S () { v++; } };
+struct S { S () { v++; } ~S () { v++; } }; // { dg-warning "deprecated" "" { target c++2a } }
__attribute__((noinline, noclone)) static void
foo (int x)
{
- v++;
+ v++; // { dg-warning "deprecated" "" { target c++2a } }
if (x == 5)
bar (x);
}
__attribute__((noinline, noclone)) static void
bar (int x)
{
- v++;
+ v++; // { dg-warning "deprecated" "" { target c++2a } }
if (x == 6)
foo (x);
else if (x == 5)
int main()
{
volatile int i = 0;
- f(i++);
+ f(i++); // { dg-warning "deprecated" "" { target c++2a } }
}
} const; // { dg-error "'const' can only be specified for objects and functions" }
void foo (
-struct E2
+struct E2 // { dg-warning "deprecated" "" { target c++2a } }
{ // { dg-error "types may not be defined in parameter types" }
int i;
} volatile);
/* { dg-options "-Wignored-qualifiers" } */
volatile void bar(); /* { dg-warning "type qualifiers ignored" } */
+// { dg-warning ".volatile.-qualified return type is deprecated" "" { target c++2a } .-1 }
struct A
{
bool a;
volatile bool b,c;
foo() { a = b = c = false; } // { dg-bogus "parentheses" }
+ // { dg-warning "deprecated" "" { target c++2a } .-1 }
};
int main() {
bool a;
volatile bool b,c;
a = b = c = false; // { dg-bogus "parentheses" }
+ // { dg-warning "deprecated" "" { target c++2a } .-1 }
foo A;
}
char * volatile p;
void foo() {
- --p = 0;
+ --p = 0; // { dg-warning "deprecated" "" { target c++2a } }
}
class f_class // { dg-message "note" "candidates" }
{ };
-volatile f_class
+volatile f_class // { dg-warning "deprecated" "" { target c++2a } }
ret_v_f_class()
{
f_class t;