[clang] [Clang][Sema] fix noexecpt mismatch of friend declaration (PR #102267)
Qizhi Hu via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 14 03:10:02 PDT 2024
jcsxky wrote:
@sdkrystian Could you please take another look at this patch? The approach does what you said before.
When checking exception specific equivalence of the two functions, we do instantiation and substitute all the template parameters with instantiated ones. But we can't find them as we create a new `LocalInstantiationScope`. So these instantiated parameters should be added to current new `LocalInstantiationScope`(like what `addInstantiatedParametersToScope` does in the following code) to make sure they can be found.
Consider the test case:
```cpp
template <typename T>
struct C {
template <int N>
friend void func() noexcept(N == 0);
};
template <int N>
void func() noexcept(N == 0) {}
int main() {
C<int> t;
return 0;
}
```
Without this patch, `Sema::FindInstantiatedDecl` returns original template parameter in transforming exception specific when trying to find instantiated parameter of `N`. So we use the original parameter(`N`) whose depth is 1 in the primary template and this is incorrect and make the comparison failed since it should be 0 in the template specialization. Adding instantiated parameters to current `LocalInstantiationScope` makes `Sema::FindInstantiatedDecl` returns the correct instantiated parameter and it works.
https://github.com/llvm/llvm-project/pull/102267
More information about the cfe-commits
mailing list