[llvm-bugs] [Bug 43733] New: Unhelpful diagnostic "qualified reference to 'A' is a constructor name rather than a type in this context"

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Oct 20 09:18:36 PDT 2019


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

            Bug ID: 43733
           Summary: Unhelpful diagnostic "qualified reference to 'A' is a
                    constructor name rather than a type in this context"
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arthur.j.odwyer at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

https://godbolt.org/z/Wy8vGG

A newbie (not me originally) wrote this:

    template<class K>
    bool foo(const K& a, const K& b) {
        return std::less<K>::less()(a, b);
    }
    int i = foo(1,2);

Compiler complains:

    <source>:5:16: error: missing 'typename' prior to
    dependent type name 'std::less<int>::less'
        return std::less<K>::less()(a, b);
               ^~~~~~~~~~~~~~~~~~

Easy peasy. Seen this error message before. Explain to newbie that they need
`typename` here (and why). Add `typename` and recompile. Compiler *still
complains!*

    <source>:5:39: warning: ISO C++ specifies that
    qualified reference to 'less' is a constructor name
    rather than a type in this context,
    despite preceding 'typename' keyword [-Winjected-class-name]
        return typename std::less<K>::less()(a, b);
                                      ^

Now this is confusing. Complains with typename, complains without typename. I
had to go to Slack and ask what was supposed to be happening here.

What the compiler should say in this second case is not just a dry note about
the standardese names for things, but specifically something that would help
the user find and fix their bug. For example:

    hypothetical error: qualified reference to 'less' names
    a constructor, not a type,
    despite preceding 'typename' keyword [-Winjected-class-name]
        return typename std::less<K>::less()(a, b);
                                      ^~~~
    hypothetical note: to construct an object of this type,
    remove the explicit constructor name
        return typename std::less<K>::less()(a, b);
               ^~~~~~~~~            ~~~~~~

And in the preceding case, where adding `typename` was precisely the wrong
"fix," Clang really should not have suggested it.

    hypothetical error: qualified reference to 'less' names
    a constructor [-Winjected-class-name]
        return std::less<K>::less()(a, b);
               ^~~~~~~~~~~~~~~~~~

    hypothetical note: to construct an object of this type,
    remove the explicit constructor name
        return std::less<K>::less()(a, b);
                           ^~~~~~

-- 
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/20191020/65640e76/attachment.html>


More information about the llvm-bugs mailing list