Skip to content

Spurious error with -fincremental-extensions in clang 16 #62413

@cov-tprince

Description

@cov-tprince

We recently started the process to upgrade our frontend to Clang 16. However, we discovered a fairly serious regression when using -fincremental-extensions:

$ cat bad.cpp
struct S {
  ~S();
};
S::~S() {}
$ /opt/pkg/clang-16/bin/clang++ -c bad.cpp
$ /opt/pkg/clang-16/bin/clang++ -c -Xclang -fincremental-extensions bad.cpp
bad.cpp:4:4: error: call to non-static member function without an object argument
S::~S() {}
~~~^
1 error generated.
$ 

Godbolt link for the above:
https://godbolt.org/z/89jfE3YWP

It's probably worth a little explanation for why we're using this obscure feature--this is an unfortunate wart relating to constraints imposed by our internal AST. When a type contains a member function template that implements a special member function (e.g. operator=) we attempt to instantiate those methods when doing AST translation even if they are not explicitly required by the translation unit. Any errors generated by this instantiation are suppressed and discarded.

However, because we're doing this instantiation after the ASTUnit is fully loaded, clang would normally tear down many of the resources needed to do template instantiations, leading to various memory errors/crashes. We use -fincremental-extensions to suppress this teardown.

In the future, we hope to do these instantiations inline with the initial ASTUnit loading which would allow us to remove our dependency on -fincremental-extensions.

We are currently in the process of trying to identify what commit or set of commits introduced this regression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions