Clang unable to diagnose missing template keyword when unrelated code is added. #36539
Labels
bugzilla
Issues migrated from bugzilla
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
Extended Description
Clang is able to diagnose a missing template keyword for good-diagnostic.cc below. However, if some unrelated code is added as in bad-diagnostic.cc below, an incorrect diagnostic about overloaded functions is emitted instead.
$ cat good-diagnostic.cc
template <typename T, int N>
struct Foo {
template
static void bar(T arr[N]) {}
};
template <typename T, int Width, int Stride>
void test() {
T in[Width];
Foo<T, Width>::bar(in);
}
void run() {
test<int, 10, 10>();
}
$ clang good-diagnostic.cc
good-diagnostic.cc:10:3: error: missing 'template' keyword prior to dependent
template name 'bar'
Foo<T, Width>::bar(in);
^
good-diagnostic.cc:14:3: note: in instantiation of function template
specialization 'test<int, 10, 10>' requested here
test<int, 10, 10>();
^
1 error generated.
$ cat bad-diagnostic.cc
struct S {};
bool run(const S a, const S b);
bool operator< (const S &s1, const S &s2) { return run(s1, s2); }
bool operator>=(const S &s1, const S &s2) { return run(s1, s2); }
bool operator<=(const S &s1, const S &s2) { return run(s1, s2); }
template <typename T, int N>
struct Foo {
template
static void bar(T arr[N]) {}
};
template <typename T, int Width, int Stride>
void test() {
T in[Width];
Foo<T, Width>::bar(in);
}
void run() {
test<int, 10, 10>();
}
$ clang bad-diagnostic.cc
bad-diagnostic.cc:18:3: error: reference to overloaded function could not be
resolved; did you mean to call it?
Foo<T, Width>::bar(in);
^~~~~~~~~~~~~~~~~~
bad-diagnostic.cc:22:3: note: in instantiation of function template
specialization 'test<int, 10, 10>' requested here
test<int, 10, 10>();
^
bad-diagnostic.cc:12:15: note: possible target for call
static void bar(T arr[N]) {}
^
1 error generated.
The text was updated successfully, but these errors were encountered: