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

(cpp) decltype(auto) preceded by specifiers #1222

Closed
Arcoth opened this issue Jun 19, 2016 · 6 comments · Fixed by #2332
Closed

(cpp) decltype(auto) preceded by specifiers #1222

Arcoth opened this issue Jun 19, 2016 · 6 comments · Fixed by #2332

Comments

@Arcoth
Copy link

Arcoth commented Jun 19, 2016

If constexpr decltype(auto) occurs in C++(14) code, decltype is not highlighted correctly, presumably since this looks like a function declaration with decltype being the name. This will also occur with other specifiers, e.g. friend, typedef, inline etc.

In fact, this can occur with keywords other than decltype. See e.g.

#define X
X new (p) int;

I'd suggest dropping that heuristic entirely.

@Sannis Sannis added the bug label Jun 19, 2016
@joshgoebel
Copy link
Member

Is this still an issue?

Wouldn't it also be resolved by simply excluding keywords from IDENT_RE so that a keyword would never count as the name of a function? I assume there is no way to name a function a reserved keyword, correct?

@joshgoebel
Copy link
Member

joshgoebel commented Oct 5, 2019

This is worth thought because the parser by default doesn't look for keywords first, it looks for "language constructs" (other parser rules) and then in-between those it will highlight any keywords. So the problem here is we first find what looks like a function and then we highlight it... so we're looking for a title at that point, not a keyword.

I wonder if this could be fixed with negative look-ahead, which is what I was hinting at.

I presume we "like" the ability to highlight function titles and that losing that would be a pretty big loss.

Can you provide a little more context regarding what constexpr decltype(auto) looks like in context of an actual C++ file?

@joshgoebel
Copy link
Member

joshgoebel commented Oct 5, 2019

#define X
X new (p) int;

We're never going to be able to handle all edge cases involving pre-processor directives - since we don't have access to the actual source - only the raw source.

@joshgoebel joshgoebel changed the title decltype(auto) preceded by specifiers (cpp) decltype(auto) preceded by specifiers Oct 13, 2019
@joshgoebel
Copy link
Member

@Arcoth Default arguments exist in C++, so couldn't one use ternary when defining a default argument? So wouldn't ? actually be valid? Might fixing that help here even if the highlighter itself was still a little confused?

@joshgoebel
Copy link
Member

This will also occur with other specifiers, e.g. friend, typedef, inline etc.

As far as I can tell these just work, the only real issue is with auto type.

After my PR:

Screen Shot 2019-12-23 at 5 43 02 PM

@joshgoebel
Copy link
Member

@Arcoth Does that look right to you?

joshgoebel added a commit that referenced this issue Jan 15, 2020
- enh(cpp) Properly detect decltype(auto)
- enh(cpp) recognize primitive types (`int8_t`, etc.) as function types
- enh(cpp) Detect namespaced function types (`A::typeName func(...)`)
- enh(cpp) Detect namespaced functions also (`A::functionName`)
- enh(cpp) template type in function declaration (`vector<int> func(...)`)

Closes #1730.
Closes #1222.
Closes #1502.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants