From: Jakub Jelinek Date: Fri, 14 Oct 2016 19:00:38 +0000 (+0200) Subject: DR 1511 - const volatile variables and ODR X-Git-Tag: upstream/12.2.0~44031 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=064ed55a66a788b1939fb93bd64ea3705e8384c7;p=platform%2Fupstream%2Fgcc.git DR 1511 - const volatile variables and ODR DR 1511 - const volatile variables and ODR * decl.c (grokvardecl): Change flags argument to type_quals, add conceptp argument. Set TREE_PUBLIC for non-static volatile vars. (grokdeclarator): Adjust grokvardecl caller. * g++.dg/DRs/dr1511-1.C: New test. * g++.dg/DRs/dr1511-2.C: New test. From-SVN: r241176 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cc16176..cdc5aff 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2016-10-14 Jakub Jelinek + + DR 1511 - const volatile variables and ODR + * decl.c (grokvardecl): Change flags argument to type_quals, + add conceptp argument. Set TREE_PUBLIC for non-static volatile vars. + (grokdeclarator): Adjust grokvardecl caller. + 2016-10-13 Martin Sebor PR c++/71912 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f761d0d..d70d583 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -68,7 +68,7 @@ static int unary_op_p (enum tree_code); static void push_local_name (tree); static tree grok_reference_init (tree, tree, tree, int); static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *, - int, int, int, int, tree); + int, int, int, bool, int, tree); static int check_static_variable_definition (tree, tree); static void record_unknown_type (tree, const char *); static tree builtin_function_1 (tree, tree, bool); @@ -8512,8 +8512,9 @@ grokvardecl (tree type, tree orig_declarator, const cp_decl_specifier_seq *declspecs, int initialized, - int flags, + int type_quals, int inlinep, + bool conceptp, int template_count, tree scope) { @@ -8522,8 +8523,8 @@ grokvardecl (tree type, gcc_assert (!name || identifier_p (name)); - bool constp = flags&1; - bool conceptp = flags&2; + bool constp = (type_quals & TYPE_QUAL_CONST) != 0; + bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0; /* Compute the scope in which to place the variable, but remember whether or not that scope was explicitly specified by the user. */ @@ -8580,6 +8581,7 @@ grokvardecl (tree type, TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static && (DECL_THIS_EXTERN (decl) || ! constp + || volatilep || inlinep)); TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); } @@ -11626,8 +11628,9 @@ grokdeclarator (const cp_declarator *declarator, decl = grokvardecl (type, dname, unqualified_id, declspecs, initialized, - ((type_quals & TYPE_QUAL_CONST) != 0) | (2 * concept_p), + type_quals, inlinep, + concept_p, template_count, ctype ? ctype : in_namespace); if (decl == NULL_TREE) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d0724f1..25115d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-10-14 Jakub Jelinek + + DR 1511 - const volatile variables and ODR + * g++.dg/DRs/dr1511-1.C: New test. + * g++.dg/DRs/dr1511-2.C: New test. + 2016-10-14 Eric Botcazou * gnat.dg/debug7.adb (dg-options): Remove -g. diff --git a/gcc/testsuite/g++.dg/DRs/dr1511-1.C b/gcc/testsuite/g++.dg/DRs/dr1511-1.C new file mode 100644 index 0000000..a24b44a --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr1511-1.C @@ -0,0 +1,38 @@ +/* DR 1511 - const volatile variables and the one-definition rule */ +/* { dg-do run } */ +/* { dg-additional-sources "dr1511-2.C" } */ + +typedef const int cint; +typedef const volatile int cvint; +typedef volatile int vint; +const int v1 = 5; +extern volatile const int v2; +cint v3 = 7; +extern cvint v4; +extern const vint v5; +extern volatile cint v6; +const int w1 = 5; +extern volatile const int w2; +cint w3 = 7; +extern cvint w4; +extern const vint w5; +extern volatile cint w6; +extern const int &r1; +extern volatile const int &r2; +extern const int &r3; +extern const volatile int &r4; +extern const volatile int &r5; +extern const volatile int &r6; + +int +main () +{ + if (v1 != 5 || v2 != 6 || v3 != 7 || v4 != 8 || v5 != 9 || v6 != 10) + __builtin_abort (); + if (w1 != 5 || w2 != 6 || w3 != 7 || w4 != 8 || w5 != 9 || w6 != 10) + __builtin_abort (); + if (r1 != w1 || &r1 == &w1 || r2 != w2 || &r2 != &w2 || r3 != w3 || &r3 == &w3) + __builtin_abort (); + if (r4 != w4 || &r4 != &w4 || r5 != w5 || &r5 != &w5 || r6 != w6 || &r6 != &w6) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/DRs/dr1511-2.C b/gcc/testsuite/g++.dg/DRs/dr1511-2.C new file mode 100644 index 0000000..fc604d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr1511-2.C @@ -0,0 +1,24 @@ +/* DR 1511 - const volatile variables and the one-definition rule */ +/* { dg-do compile } */ + +typedef const int cint; +typedef const volatile int cvint; +typedef volatile int vint; +const int v1 = 5; +volatile const int v2 = 6; +cint v3 = 7; +cvint v4 = 8; +const vint v5 = 9; +volatile cint v6 = 10; +const int w1 = 5; +volatile const int w2 = 6; +cint w3 = 7; +cvint w4 = 8; +const vint w5 = 9; +volatile cint w6 = 10; +const int &r1 = w1; +volatile const int &r2 = w2; +const int &r3 = w3; +const volatile int &r4 = w4; +const volatile int &r5 = w5; +const volatile int &r6 = w6;