Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"error: identifier 'line' after '~' in destructor name does not name a type" in struct line that has line member #88597

Open
nabijaczleweli opened this issue Apr 13, 2024 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@nabijaczleweli
Copy link

#include <string_view>

struct line {
	std::string_view line;
	~line() {
		line = {};
	}
};

trunk returns

<source>:5:3: error: identifier 'line' after '~' in destructor name does not name a type

cmd/join.cpp:49:5: error: identifier 'line' after '~' in destructor name does not name a type
   49 |                         ~line() {
      |                          ^~~~
      |                          line
cmd/join.cpp:32:21: note: non-type declaration found by destructor name lookup
   32 |                         std::string_view line;
      |                                          ^

older versions return

<source>:5:3: error: expected the class name after '~' to name a destructor

All GCC versions accept this.

Don't particularly see why the member would factor into the lookup at all here, but it's not like I can call this ~(struct line)() { or ~struct line() {.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Apr 13, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 13, 2024

@llvm/issue-subscribers-clang-frontend

Author: наб (nabijaczleweli)

```cpp #include <string_view>

struct line {
std::string_view line;
~line() {
line = {};
}
};

trunk returns
&gt; &amp;lt;source&gt;:5:3: error: identifier 'line' after '~' in destructor name does not name a type

cmd/join.cpp:49:5: error: identifier 'line' after '~' in destructor name does not name a type
49 | ~line() {
| ^~~~
| line
cmd/join.cpp:32:21: note: non-type declaration found by destructor name lookup
32 | std::string_view line;
| ^


older versions return
&gt; &amp;lt;source&gt;:5:3: error: expected the class name after '~' to name a destructor

All GCC versions accept this.

Don't particularly see why the member would factor into the lookup at all here, but it's not like I can call this `~(struct line)() {` or `~struct line() {`.
</details>

@shafik
Copy link
Collaborator

shafik commented Apr 13, 2024

Reduced: https://godbolt.org/z/EeGn5vTrY

struct line {
	int line;
	~line();
};

It looks like rule here is set by cwg80:

In addition, if class T has a user-declared constructor (11.4.5 [class.ctor] ), every nonstatic data member of class T shall have a name different from T.

see class.mem.general p24

So this applies to constructors but not destructors.

We handle this here:

Diag(NameLoc, SearchType.isNull() ? diag::err_destructor_name_nontype
: diag::err_destructor_expr_mismatch)
<< &II << SearchType << MakeFixItHint();

I think we need to handle the case where FoundDecls.size() == 2 and it is non-static data member.

@nabijaczleweli
Copy link
Author

In this case it looks like this is FoundDecls.size() == 1 and SearchType.isNull().

nabijaczleweli added a commit to nabijaczleweli/llvm-project that referenced this issue Apr 15, 2024
nabijaczleweli added a commit to nabijaczleweli/llvm-project that referenced this issue Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants