question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C++ : Trailing return types in function declaration result in illegal language match

See original GitHub issue

Describe 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 and highlightElement behaviors
  • Proper modern and post-modern C++ synthaxes match & detection

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Dec 10, 2022

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. 😃

0reactions
GuillaumeDuacommented, Dec 12, 2022

Correct. 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found