https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119182

            Bug ID: 119182
           Summary: Compiler Fails to Diagnose Redefinition of Type Alias
                    in Lambda Scope
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qurong at ios dot ac.cn
  Target Milestone: ---

The compiler silently accepts code that redefines a type alias (`using`) within
the same lambda scope, while Clang correctly issues a warning. This violates
C++17 §10.1.3, which prohibits redefining type aliases in the same scope and
requires a diagnostic.  

**Steps to Reproduce**:  
1. Save the following code as `test.cpp`:  
   ```cpp  
   template <typename T>  
   struct Test {  
       int f() {  
           int x = 0;  
           [x = x, &r = x] {  
               using ty1 = int;         // First definition  
               using ty1 = decltype(x); // Redefinition (invalid)  
           };  
           return 0;  
       }  
   };  

   int main() {  
       Test<int> obj;  
       obj.f();  
       return 0;  
   }  
```

2. Compile with GCC:
g++ -std=c++17 test.cpp    

Expected Result:
A diagnostic (error/warning) about the redefinition of ty1.

Actual Result:
GCC compile the code without any errors or warnings.

Environment:
Compiler: GCC 13.2.0
Flags: -std=c++17

Proposal:
Reject the code or emit a diagnostic for redefined type aliases in the same
scope, as required by the standard.

Additional Notes:
Standard Reference: C++17 §10.1.3:
"A type-name introduced by a using declaration shall be unique in the
declarative region in which it appears."
Clang Behavior: Correctly warns with warning: redefinition of type alias 'ty1'.

Compiler Explorer link: https://godbolt.org/z/xEMrnbrW4

Reply via email to