TPPPP72 wrote:

@ojhunt 

Because this PR triggered regression #195416 , I did some research.

```cpp
|-FunctionTemplateDecl 0x7dd670c51268 <repro.cpp:1:1, line:5:1> line:1:27 f 
external-linkage
| |-TemplateTypeParmDecl 0x7dd670c50f78 <col:11, col:20> col:20 referenced 
typename depth 0 index 0 T
| |-FunctionDecl 0x7dd670c511b8 <col:23, line:5:1> line:1:27 f 'int (T)'
| | |-ParmVarDecl 0x7dd670c51090 <col:29> col:30 'T'
| | `-CompoundStmt 0x7dd670c51628 <col:32, line:5:1>
| |   `-DeclStmt 0x7dd670c51608 <line:2:3, line:4:4>
| |     `-CXXRecordDecl 0x7dd670c51398 <line:2:3, line:4:3> line:2:10 struct A 
definition
| |       |-DefinitionData empty aggregate standard_layout trivially_copyable 
pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
| |       | |-DefaultConstructor exists trivial constexpr needs_implicit 
defaulted_is_constexpr
| |       | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
| |       | |-MoveConstructor exists simple trivial needs_implicit
| |       | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
| |       | |-MoveAssignment exists simple trivial needs_implicit
| |       | `-Destructor simple irrelevant trivial needs_implicit
| |       |-CXXRecordDecl 0x7dd670c514a0 <col:3, col:10> col:10 implicit struct 
A
| |       `-VarDecl 0x7dd670c51550 <line:3:5, col:16> col:16 invalid B 'int' 
static
| `-FunctionDecl 0x7dd670c77538 <line:1:23, line:5:1> line:1:27 used f 'int 
(int)' implicit_instantiation instantiated_from 0x7dd670c511b8 external-linkage
|   |-TemplateArgument type 'int'
|   | `-BuiltinType 0x7dd670bfba70 'int'
|   |-ParmVarDecl 0x7dd670c517f8 <col:29> col:30 'int'
|   `-CompoundStmt 0x7dd670c779d8 <col:32, line:5:1>
|     `-DeclStmt 0x7dd670c779b8 <line:2:3, line:4:4>
|       `-CXXRecordDecl 0x7dd670c777b0 <line:2:3, line:4:3> line:2:10 invalid 
struct A definition instantiated_from 0x7dd670c51398
|         |-DefinitionData empty aggregate standard_layout trivially_copyable 
pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
|         | |-DefaultConstructor exists trivial constexpr needs_implicit 
defaulted_is_constexpr
|         | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
|         | |-MoveConstructor exists simple trivial needs_implicit
|         | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
|         | |-MoveAssignment exists simple trivial needs_implicit
|         | `-Destructor simple irrelevant trivial needs_implicit
|         `-CXXRecordDecl 0x7dd670c778d0 <col:3, col:10> col:10 implicit struct 
A
```

The real reason for this problem is that the instantiated `Var` is not checked 
for a valid context before calling `SubstQualifier`. Therefore, interception 
should be performed at the `VisitVarDecl` stage instead of directly marking the 
entire struct in the template as invalid. In other words, we should not mark 
uninstantiated template members as invalid.

Even if we don't set the class definition inside the template to invalid, 
invalidity can be automatically inferred during the instantiation phase, so the 
current information is actually sufficient.

The current solution is calling `setInvalidDecl` on `CXXRecord`. According to 
regression issues, this clearly violates some convention regarding upstream and 
downstream data.

Furthermore, given the context, there is no reason for us to call `set` here 
(the original code used `const`).

https://github.com/llvm/llvm-project/pull/182707
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to