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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to