This is an archive of the discontinued LLVM Phabricator instance.

Fix a diagnoses-valid bug with using declarations
ClosedPublic

Authored by aaron.ballman on Jun 1 2021, 12:49 PM.

Details

Summary

The following was found by a customer and is accepted by the other primary C++ compilers, but fails to compile in Clang:

namespace sss {
double foo(int, double);
template <class T>
T foo(T); // note: target of using declaration
}  // namespace sss

namespace oad {
void foo();
}

namespace oad {
using ::sss::foo;
}

namespace sss {
using oad::foo; // note: using declaration
}

namespace sss {
double foo(int, double) { return 0; }
template <class T>
T foo(T t) { // error: declaration conflicts with target of using declaration already in scope
  return t;
}
}  // namespace sss

I believe the issue is that MergeFunctionDecl() was calling checkUsingShadowRedecl() but only considering a FunctionDecl as a possible shadow and not FunctionTemplateDecl. The changes in this patch largely mirror how variable declarations were being handled by also catching FunctionTemplateDecl.

Diff Detail

Event Timeline

aaron.ballman requested review of this revision.Jun 1 2021, 12:49 PM
aaron.ballman created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2021, 12:49 PM

The patch looks fine to me, though I don't particularly get the test changes that move a diagnostic by 1 line?

The patch looks fine to me, though I don't particularly get the test changes that move a diagnostic by 1 line?

The global-vs-module.cpp test had a line removed from it for the FIXME comment. The module-vs-module.cpp and module-vs-global.cpp files both reference diagnostics by line within global-vs-module.cpp, so those lines all had to be adjusted accordingly.

erichkeane accepted this revision.Jun 1 2021, 12:59 PM

Ah! Thats what I missed!

This revision is now accepted and ready to land.Jun 1 2021, 12:59 PM
aaron.ballman closed this revision.Jun 4 2021, 1:00 PM

Thanks for the review! I've commit in ca68f3bc48e48f839142de1461e95d87ae48e9df.