[llvm-bugs] [Bug 25977] New: Poor diagnostic when forgetting to repeat default template type parameter

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 30 11:34:19 PST 2015


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

            Bug ID: 25977
           Summary: Poor diagnostic when forgetting to repeat default
                    template type parameter
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Consider this program:

template<typename T> struct DefaultTraits;
template<typename T, typename Traits = DefaultTraits<T>>
struct ScopedTypeRef {
  ScopedTypeRef(T object = Traits::InvalidValue()) {}
};

template <typename NST>
struct PointerTraits {
  static NST InvalidValue() { return nullptr; }
};

template <typename NST>
class scoped_nsprotocol : public ScopedTypeRef<NST, PointerTraits<NST>> {
 public:
  using ScopedTypeRef<NST>::ScopedTypeRef;
};

int main() {
  scoped_nsprotocol<int*> array(new int);
}

clang complains:

thakis at thakis:~/Downloads$ ~/src/llvm-build/bin/clang -c
templated-inherited-ctor.cc  -std=c++11 
templated-inherited-ctor.cc:15:9: error: using declaration refers into
'ScopedTypeRef<int *>::', which is not a base class of
      'scoped_nsprotocol<int *>'
  using ScopedTypeRef<NST>::ScopedTypeRef;
        ^~~~~~~~~~~~~~~~~~~~
templated-inherited-ctor.cc:19:27: note: in instantiation of template class
'scoped_nsprotocol<int *>' requested here
  scoped_nsprotocol<int*> array(new int);
                          ^
templated-inherited-ctor.cc:19:27: error: no matching constructor for
initialization of 'scoped_nsprotocol<int *>'
  scoped_nsprotocol<int*> array(new int);
                          ^     ~~~~~~~
templated-inherited-ctor.cc:13:7: note: candidate constructor (the implicit
copy constructor) not viable: no known conversion from
      'int *' to 'const scoped_nsprotocol<int *>' for 1st argument
class scoped_nsprotocol : public ScopedTypeRef<NST, PointerTraits<NST>> {
      ^
templated-inherited-ctor.cc:13:7: note: candidate constructor (the implicit
move constructor) not viable: no known conversion from
      'int *' to 'scoped_nsprotocol<int *>' for 1st argument
class scoped_nsprotocol : public ScopedTypeRef<NST, PointerTraits<NST>> {
      ^
templated-inherited-ctor.cc:13:7: note: candidate constructor (the implicit
default constructor) not viable: requires 0 arguments,
      but 1 was provided
2 errors generated.


The fix is to change
  using ScopedTypeRef<NST>::ScopedTypeRef;
into
  using ScopedTypeRef<NST, PointerTraits<NST>>::ScopedTypeRef;
which isn't very clear from the error. If the base class is a template with
some default args and the default args are not explicitly passed in, then we
could emit a better diagnostic in that case.

-- 
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/20151230/68c13c24/attachment.html>


More information about the llvm-bugs mailing list