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

            Bug ID: 110128
           Summary: copy attribute does not copy from template
                    specializations
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jwjagersma at gmail dot com
  Target Milestone: ---

Given the following example:


    template<int>
    void check_num();

    template<> [[gnu::warning("unlucky number")]]
    void check_num<13>();

    template<> [[gnu::error("evil number")]]
    void check_num<666>();


    template<int I> [[gnu::copy(check_num<I>)]]
    int num() { return I; }

    int main()
    {
        return num<42>() + num<13>() + num<666>();
    }


GCC only produces a number of -Wattributes warnings:


    $ g++ test-copy.cpp
    test-copy.cpp: In substitution of ‘template<int I> int num() [with int I =
42]’:
    test-copy.cpp:16:19:   required from here
    test-copy.cpp:12:5: warning: ‘copy’ attribute ignored on a declaration of a
different kind than referenced symbol [-Wattributes]
       12 | int num() { return I; }
          |     ^~~
    test-copy.cpp: In substitution of ‘template<int I> int num() [with int I =
13]’:
    test-copy.cpp:16:31:   required from here
    test-copy.cpp:12:5: warning: ‘copy’ attribute ignored on a declaration of a
different kind than referenced symbol [-Wattributes]
    test-copy.cpp: In substitution of ‘template<int I> int num() [with int I =
666]’:
    test-copy.cpp:16:44:   required from here
    test-copy.cpp:12:5: warning: ‘copy’ attribute ignored on a declaration of a
different kind than referenced symbol [-Wattributes]


PR89309 claims these are only spurious, but in this case they are not.  The
attributes are not copied.

Reply via email to