[llvm-bugs] [Bug 44558] New: Nodiscard warning diagnosed twice when called in a template:

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 15 08:42:10 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=44558

            Bug ID: 44558
           Summary: Nodiscard warning diagnosed twice when called in a
                    template:
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: erich.keane at intel.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

https://godbolt.org/z/LesWP4

[[nodiscard]] int* bar();

template<typename T>
void foo() {
    bar();
}

void baz() {
    foo<int>();
}

<source>:7:5: warning: ignoring return value of function declared with
'nodiscard' attribute [-Wunused-result]

    bar();

    ^~~

<source>:7:5: warning: ignoring return value of function declared with
'nodiscard' attribute [-Wunused-result]

    bar();

    ^~~

<source>:11:5: note: in instantiation of function template specialization
'foo<int>' requested here

    foo<int>();


The warning should likely only happen 1x, but we end up diagnosing it 2x.  We
suppress 'errors' by marking the template invalid (and thus uncallable), but
don't do so with warnings.

-- 
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/20200115/e96a0e50/attachment.html>


More information about the llvm-bugs mailing list