================
@@ -2282,7 +2282,8 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
 
     // Remove this name from our lexical scope, and warn on it if we haven't
     // already.
-    IdResolver.RemoveDecl(D);
+    if (!PP.isIncrementalProcessingEnabled())
+      IdResolver.RemoveDecl(D);
----------------
vgvassilev wrote:

No, this change makes sure that we preserve the state of the `IdResolver` 
across partial translation units (PTU). That is, when we see another 
incremental output, we still take into account the declarations that came from 
previous PTUs. Eg:

```
[repl] int i = 12;
[repl] printf("%d\n", i); // without this patch we report we do not know what 
`i` is...
```

To your explicit question this patch produces:

```
bin/clang-repl -Xcc -xc
clang-repl> { int i = 12; }
clang-repl> printf("%d", i); // Fine?
In file included from <<< inputs >>>:1:
input_line_2:1:1: error: call to undeclared library function 'printf' with type 
'int (const char *, ...)'; ISO C99 and later do not support implicit function 
declarations [-Wimplicit-function-declaration]
    1 | printf("%d", i); // Fine?
      | ^
input_line_2:1:1: note: include the header <stdio.h> or explicitly provide a 
declaration for 'printf'
input_line_2:1:14: error: reference to local variable 'i' declared in enclosing 
context
    1 | printf("%d", i); // Fine?
      |              ^
input_line_1:1:7: note: 'i' declared here
    1 | { int i = 12; }
      |       ^
error: Parsing failed.
clang-repl> %quit
```

https://github.com/llvm/llvm-project/pull/89804
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to