Skip to content

[BUG] alias: type == _ generates invalid cpp1 #357

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

Closed
realgdman opened this issue Apr 11, 2023 · 4 comments · Fixed by #360
Closed

[BUG] alias: type == _ generates invalid cpp1 #357

realgdman opened this issue Apr 11, 2023 · 4 comments · Fixed by #360
Labels
bug Something isn't working

Comments

@realgdman
Copy link

Minimal reproduce
alias5: type == _;
passes succssfully cpp2, but generates invalid cpp1:
using alias5 = auto;

Command lines including which C++ compiler you are using
cppfront example.cpp2 -p
(build from latest mai. f83ca9b with clang++-15)
Then cpp1 compiled with
clang++-15 -Icppfront/include $1.cpp -std=c++20 -o $1

Actual result/error
Cppfront passes with
example.cpp2... ok (all Cpp2, passes safety checks)
But then clang fails with
error: 'auto' not allowed in type alias using alias5 = auto;

Expected result
Diagnostic at cpp2 side. (I guess that`s strategy, to catch whatever possible cpp2 relateed before relying on cpp1 compiler?)

Additional context
This is extreme case, because clang says auto is never allowed.
There is other case
alias6: type == foo when foo is not defined generates correct
using alias6 = foo;
But I guess this can be separate issue, for should cppfront check if alias goes to something undefined.

@realgdman realgdman added the bug Something isn't working label Apr 11, 2023
@JohelEGP
Copy link
Contributor

But I guess this can be separate issue, for should cppfront check if alias goes to something undefined.

This is better left off to the C++1 compiler to diagnose. Otherwise, cppfront would have to be a C++1 compiler to know if it's ill-formed.

@filipsajdak
Copy link
Contributor

We can diagnose cases like:

alias5: type == _;

filipsajdak added a commit to filipsajdak/cppfront that referenced this issue Apr 11, 2023
In the current implementation of cppfront (f83ca9) the following code:
```cpp
alias5: type == _;
```
Generates succesfuly:
```cpp
using alias5 = auto;
```
Which is invalid cpp1 code.

After this change the alias to wildcard will generate the following error:
```
a 'type ==' alias declaration must be followed by a type name and not a wildcard _
```

All regression tests pass. Closes hsutter#357
@filipsajdak
Copy link
Contributor

Change that provides diagnostics for a wildcard: #360

filipsajdak added a commit to filipsajdak/cppfront that referenced this issue Apr 12, 2023
In the current implementation of cppfront (f83ca9) the following code:
```cpp
alias5: type == _;
alias6: type == auto;
```
Generates succesfuly:
```cpp
using alias5 = auto;
using alias6 = auto;
```
Which is invalid cpp1 code.

After this change the alias to wildcard will generate the following error:
```
error: a 'type ==' alias declaration must be followed by a type name (not a wildcard _ nor auto)
```

All regression tests pass. Closes hsutter#357
@realgdman
Copy link
Author

Great.
BTW what do you think about cases like that? Currently they're passed successfully to cpp1 and fail there.
alias8: == ();
alias9: == (int);

filipsajdak added a commit to filipsajdak/cppfront that referenced this issue Apr 16, 2023
In the current implementation of cppfront (f83ca9) the following code:
```cpp
alias5: type == _;
alias6: type == auto;
```
Generates succesfuly:
```cpp
using alias5 = auto;
using alias6 = auto;
```
Which is invalid cpp1 code.

After this change the alias to wildcard will generate the following error:
```
error: a 'type ==' alias declaration must be followed by a type name (not a wildcard _ nor auto)
```

All regression tests pass. Closes hsutter#357
hsutter pushed a commit that referenced this issue Apr 16, 2023
In the current implementation of cppfront (f83ca9) the following code:
```cpp
alias5: type == _;
alias6: type == auto;
```
Generates succesfuly:
```cpp
using alias5 = auto;
using alias6 = auto;
```
Which is invalid cpp1 code.

After this change the alias to wildcard will generate the following error:
```
error: a 'type ==' alias declaration must be followed by a type name (not a wildcard _ nor auto)
```

All regression tests pass. Closes #357
zaucy pushed a commit to zaucy/cppfront that referenced this issue Dec 5, 2023
…tter#360)

In the current implementation of cppfront (f83ca9) the following code:
```cpp
alias5: type == _;
alias6: type == auto;
```
Generates succesfuly:
```cpp
using alias5 = auto;
using alias6 = auto;
```
Which is invalid cpp1 code.

After this change the alias to wildcard will generate the following error:
```
error: a 'type ==' alias declaration must be followed by a type name (not a wildcard _ nor auto)
```

All regression tests pass. Closes hsutter#357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants