llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.06k stars 11.98k forks source link

Non-const template argument diagnostics not helpful #13040

Open llvmbot opened 12 years ago

llvmbot commented 12 years ago
Bugzilla Link 12668
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

Given this code, clang++ should diagnose that 'x' is not a constant, and thus can't be used as a template argument.

template<int I>
void foo()
{
  int x = I;
  foo<x>();
}

This actually results in "error: no matching member function for call to 'foo'" with a final notice of "note: candidate template ignored: invalid explicitly-specified argument for template parameter 'I'".

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 12 years ago

Given this code, clang++ should diagnose that 'x' is not a constant, and thus can't be used as a template argument.

We would need to be more specific than that: 'x' is not a constant, and does not denote an object of static storage duration, and is not of a class type with a constexpr conversion operator, and is not of type std::nullptr_t.

Or perhaps we should improve the note (to explain why the argument is invalid for the one-and-only candidate).