https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124399

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:e3adcc8098b8fe68efa4c7c723f264c3497a6dd5

commit r16-8098-ge3adcc8098b8fe68efa4c7c723f264c3497a6dd5
Author: Jakub Jelinek <[email protected]>
Date:   Sat Mar 14 20:48:28 2026 +0100

    c++: Ensure proper ordering of annotations in grokdeclarator [PR124399]

    For the cases in the new test like
    [[=1]] int a [[=2]], b [[=3]];
    we want to order the =1 annotation before =2 or =3 because
    https://eel.is/c++draft/meta.reflection#annotation-2.sentence-2
    and =1 precedes =2 and =3.
    The way we merge the attribute lists in grokdeclarator is done
    for speed and memory efficiency though, so we attr_chainon
    *attrlist (i.e. =1 above) after declarator->std_attributes
    (i.e. =2 or =3 above).  That has the advantage that we can keep
    sharing the earlier *attrlist between multiple declarations, each one
    will have its custom attributes at the start (if any) and then
    a shared tail with the shared ones.

    The following patch fixes it by checking if annotations are in
    both lists (otherwise we keep doing what we've been doing before).
    If they are in both, we chainon them the other way but of course
    need to copy_list to unshare the shared one for that.

    2026-03-14  Jakub Jelinek  <[email protected]>

            PR c++/124399
            * decl.cc (grokdeclarator): If both *attrlist and
            declarator->std_attributes list contain annotations, chainon
            declarator->std_attributes to tail of copy_list (*attrlist)
            rather than *attrlist to tail of declarator->std_attributes.

            * g++.dg/reflect/annotations12.C: Uncomment two tests, remove
            temporary test added until that is fixed.
            * g++.dg/reflect/annotations13.C: New test.

    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to