Skip to content

Commit

Permalink
Add diagnostics for type alias to a wildcard, closes #357 (#360)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
filipsajdak authored Apr 16, 2023
1 parent 19132f1 commit 65fcd0f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5628,6 +5628,16 @@ class parser
);
return {};
}
if (
t->is_wildcard()
|| ( t->get_token() && t->get_token()->to_string(true) == "auto" )
) {
errors.emplace_back(
curr().position(),
"a 'type ==' alias declaration must be followed by a type name (not a wildcard _ nor auto)"
);
return {};
}
a->initializer = std::move(t);
}

Expand Down

0 comments on commit 65fcd0f

Please sign in to comment.