[llvm-bugs] [Bug 38302] New: Attributes on templates are mishandled

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 24 21:18:26 PDT 2018


            Bug ID: 38302
           Summary: Attributes on templates are mishandled
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arthur.j.odwyer at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

cat >test.cc <<EOF
// https://godbolt.org/g/pqog4L
template<class T>
[[noreturn]] void one();

void one<int>() {}

template<class T>
void two();

[[noreturn]] void two<int>() {}

clang++ -std=c++2a -c test.cc

As far as I can tell, this program produces bogus diagnostics in both
First, the explicit specialization `one<int>` seems to be inheriting
`[[noreturn]]` from the primary template; I believe this is unwanted behavior.

    test.cc:2:18: warning: function declared 'noreturn' should not return
    void one<int>() {}

Second, Clang complains that the explicit specialization `two<int>` is marked
`[[noreturn]]` when its "first declaration" is not so marked. Clang seems to be
considering the primary template as the "first" declaration of every
specialization (even though the accompanying note nonsensically points to the
specialization's own declaration). This is problematic, because maybe the
programmer wants to apply `[[noreturn]]` NOT to ALL possible instantiations of
the primary template, but only to this one explicit specialization.

    test.cc:9:3: error: function declared '[[noreturn]]' after its first
    [[noreturn]] void two<int>() {}
    test.cc:9:19: note: declaration missing '[[noreturn]]' attribute is here
    [[noreturn]] void two<int>() {}

After some discussion on Slack, I think what ought to happen here is that the
attribute on the primary template ought to be applied only to instantiations
that come directly from that primary (unspecialized) template; and the
attribute on the explicit specialization ought to be applied only to that
explicit specialization. But we see that Clang doesn't do either of those

This is highly relevant to my interests because of P1144
[[trivially_relocatable]], and I'd love to put together a patch to fix it, but
at least at the moment I'm completely lost as to where I would even start

See also: https://bugs.llvm.org/show_bug.cgi?id=20758

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180725/1529259a/attachment.html>

More information about the llvm-bugs mailing list