You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Type of this can't use the current type beyond its full name #471
It's common to alias complicated base types.
Cpp2's member declaration order suggests a nested type could be used for a this member.
But it's not generally possible for the lowered Cpp1 to make use of it
(it's directly impossible,
and only for the simple cases could cppfront recursively replace nested types for their initializer).
changed the title [-][BUG] Type of `this` can't be a nested type[/-][+][BUG] Type of `this` can't use the current type beyond its full name[/+]on Jul 6, 2023
main.cpp2:1:66: error: use of class template 't' requires template arguments
1 | template<typename T> class t: public std::ranges::view_interface<t> {
| ^
This is similar in theme to #704.
In Cpp1, the expectation is that you can use names in a scope that are declared
(or will be in type scope; limitations apply).
That declaration could be in a previous statement, or lexically earlier in the current statement.
Because Cppfront lowers Cpp2 to Cpp1, the same expectation can fail to apply to Cpp2 source code.
Activity
realgdman commentedon May 25, 2023
Is this supposed to work? I can't get it to work in cpp1 either. But if aliases/using moved outside, before class, its fine.
https://cpp.godbolt.org/z/cKb38erdo
https://cpp2.godbolt.org/z/xrYe7K9ab
JohelEGP commentedon May 26, 2023
If you put a type alias before a
thismember, it generates bad code:The code in the OP is wrong.
Nested types aren't order-independent: https://compiler-explorer.com/z/7761n18Ej.
JohelEGP commentedon Jul 6, 2023
The issue is also relevant when the type of a member-as-base uses the type's template parameters.
From commit 7e80110:
JohelEGP commentedon Jul 6, 2023
Title: Type of
thismember can't be a template parameter of the current type.Description:
See #478 (comment), which also applies to the type.
Minimal reproducer (https://cpp2.godbolt.org/z/o5YE6n34f):
Commands:
cppfront main.cpp2 clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cppExpected result: I don't know. Maybe make the emitted base type a template.
Actual result and error:
Cpp2 lowered to Cpp1:
[-][BUG] Type of `this` can't be a nested type[/-][+][BUG] Type of `this` can't use the current type beyond its full name[/+]JohelEGP commentedon Jul 6, 2023
I have changed the issue's title to
This works (https://cpp2.godbolt.org/z/xzr8G1roe):
But not attempting to use
tas an injected-class-name (https://cpp2.godbolt.org/z/EfEErWMe6):That's why I use "full name".
JohelEGP commentedon Aug 14, 2023
Members before bases also can't use template parameters.
With the algorithms from #533, it'd be possible to fix that.
See https://cpp2.godbolt.org/z/vE3zohhfG:
JohelEGP commentedon Sep 30, 2023
This is similar in theme to #704.
In Cpp1, the expectation is that you can use names in a scope that are declared
(or will be in type scope; limitations apply).
That declaration could be in a previous statement, or lexically earlier in the current statement.
Because Cppfront lowers Cpp2 to Cpp1, the same expectation can fail to apply to Cpp2 source code.
JohelEGP commentedon Nov 6, 2023
#471 (comment) now segfaults: https://cpp2.godbolt.org/z/qc8v8h4Wh.