Skip to content

[clang] Regression: Tag lookup implementation edge case doesn't produce necessary diagnostic #152790

@fnriv

Description

@fnriv

Consider the following test for the C++ 20 standard:

// Copyright © 2025, Solid Sands B.V.

enum animals { penguin, lion, tiger };
namespace zoo {
    namespace animals {
        int lion = 1;
    }
}

int main() {
   animals a;

   using namespace zoo;
   using enum animals; /* Diagnostic expected */

   a = lion;

   return a == lion; 

} 

When running the below command, there should be an error diagnostic regarding the ambiguous reference to animals that is no longer produced in the current HEAD of main:

Command: clang -std=c++20 {path_to_test}

Expected output:

clang/test/sandbox/enum_ambiguous_test.C:14:15: error: reference to 'animals' is ambiguous
   14 |    using enum animals; /* Diagnostic expected */
      |               ^
clang/test/sandbox/enum_ambiguous_test.C:3:6: note: candidate found by name lookup is 'animals'
    3 | enum animals { penguin, lion, tiger };
      |      ^
clang/test/sandbox/enum_ambiguous_test.C:5:15: note: candidate found by name lookup is 'zoo::animals'
    5 |     namespace animals {
      |               ^
1 error generated.

I found this issue found by running SuperTest by Solid Sands. I ran a git bisect to find the commit that caused the diagnostic to disappear, which identified PR #112166. The PR acknowledges that there may be some edge cases to the tag lookup, and I believe this is one of them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions