C++ : Trailing return types in function declaration result in illegal language match
See original GitHub issueDescribe the issue/behavior that seems buggy
hljs.highlightAuto
does not work on the following example, while hljs.highlightElement
does.
Sample Code or Instructions to Reproduce
hljs.highlightAuto("auto main() -> int {\n auto i = 42; // test\n return i;\n}", [ 'cpp' ])
// result :
{
"language": "cpp",
"value": "auto main() -> int {\n auto i = 42; // test\n return i;\n}",
"illegal": true,
"relevance": 0,
"_illegalBy": {
"message": "Illegal lexeme \"-\" for mode \"function\"",
"index": 11,
"context": "auto main() -> int {\n auto i = 42; // test\n return i;\n}",
"mode": {},
"resultSoFar": ""
},
...
}
This issue seems to be related to the arrow ->
(feature name : trailing return type
), which is legal in post-modern C++.
See the documentation of function declaration, section (2)
(C++11), here on cppreference :
Expected behavior
- Consistency between
highlightAuto
andhighlightElement
behaviors - Proper modern and post-modern C++ synthaxes match & detection
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Trailing return type (C++11) - IBM
The trailing return type feature removes a C++ limitation where the return type of a function template cannot be generalized if the return...
Read more >Is using explicit return type in one translation unit and ...
[dcl.fct]/1 covers function declarators that do not include a trailing-return-type [emphasis mine, removing opt parts of the grammar that do ...
Read more >8. Compound statements — Python 3.11.1 documentation
Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way.
Read more >C++23: How lambdas are going to change?
So the following lambda declaration is illegal in C++20: 1 2 // warning: ... Change the scope of lambda trailing-return-type I found overly ......
Read more >LLVM Language Reference Manual
It is illegal for a global variable or function declaration to have any linkage type other than external or extern_weak .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
PR welcome… we’re going to change the auto-detect stuff a lot in v12… and remove it from our test suite… it’s just too flakey and not great in any case… so changes like this will be trivial then - if you make it now you might have to fight with auto-detect getting a bunch of things wrong that now incorrectly flag as C++. But anyone is welcome to make a PR and we’l see. 😃
Correct. 👍