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

            Bug ID: 81605
           Summary: -Wignored-attributes emitted when decltype(function)
                    used in template for function with __nonnull__
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bloerwald at googlemail dot com
  Target Milestone: ---

When using the type of a function with attribute __nonnull__ as a template
parameter, -Wignored-attributes is emitted. With other attributes, like
__noreturn__, no warning is given. Emitting the warning seems wrong since
attributes are not part of a typename and thus can't be handled by e.g. c++17's
std::is_invocable.

Tested with 6.1.0 (afaik -Wignored-attributes was introduced in 6) and 7.1.0.
Not tested with trunk/8.

    $ cat gcc_ignored_attributes.cpp 
    int fun() __attribute__((ATTRIBUTE));

    template<typename> auto templ = 0;
    auto x = templ<decltype(fun)>;

    $ gcc/6.1.0/bin/g++ --std=c++14 -c gcc_ignored_attributes.cpp -o/dev/null
-DATTRIBUTE=__nonnull__
    gcc_ignored_attributes.cpp:4:10: warning: ignoring attributes on template
argument ‘int()’ [-Wignored-attributes]
     auto x = templ<decltype(fun)>;
              ^~~~~~~~~~~~~~~~~~~~
    $ gcc/6.1.0/bin/g++ --std=c++14 -c gcc_ignored_attributes.cpp -o/dev/null
-DATTRIBUTE=__noreturn__
    $ clang/4.0.1/bin/clang++ --std=c++14 -c gcc_ignored_attributes.cpp
-o/dev/null -DATTRIBUTE=__nonnull__
    $ clang/4.0.1/bin/clang++ --std=c++14 -c gcc_ignored_attributes.cpp
-o/dev/null -DATTRIBUTE=__noreturn__
    $

Reply via email to