[all-commits] [llvm/llvm-project] fc0253: [Clang][Sema] Diagnose function/variable templates...
Krystian Stasiowski via All-commits
all-commits at lists.llvm.org
Wed Jan 17 06:13:31 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: fc0253264445be7f88d4cf0f9129dcb10c2fb84b
https://github.com/llvm/llvm-project/commit/fc0253264445be7f88d4cf0f9129dcb10c2fb84b
Author: Krystian Stasiowski <sdkrystian at gmail.com>
Date: 2024-01-17 (Wed, 17 Jan 2024)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/lib/Sema/SemaDecl.cpp
M clang/test/CXX/temp/temp.res/temp.local/p6.cpp
Log Message:
-----------
[Clang][Sema] Diagnose function/variable templates that shadow their own template parameters (#78274)
Previously, we skipped through template parameter scopes (until we hit a
declaration scope) prior to redeclaration lookup for declarators. For
template declarations, the meant that their template parameters would
not be found and shadowing would not be diagnosed. With these changes
applied, the following declarations are correctly diagnosed:
```cpp
template<typename T> void T(); // error: declaration of 'T' shadows template parameter
template<typename U> int U; // error: declaration of 'U' shadows template parameter
```
The reason for skipping past non-declaration & template parameter scopes
prior to lookup appears to have been because `GetTypeForDeclarator`
needed this adjusted scope... but it doesn't actually use this parameter
anymore.
The scope adjustment now happens prior to calling
`ActOnFunctionDeclarator`/`ActOnVariableDeclarator`/`ActOnTypedefDeclarator`
(just in case they depend on this behavior... I didn't check in depth).
More information about the All-commits
mailing list