Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang unable to diagnose missing template keyword when unrelated code is added. #36539

Open
Weverything opened this issue Apr 21, 2018 · 0 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@Weverything
Copy link
Contributor

Bugzilla Link 37191
Version unspecified
OS Linux
CC @dwblaikie

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.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

1 participant