highlightjs/highlight.js

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

Open

#3673 aperta il 8 dic 2022

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)JavaScript (3497 fork)batch import
auto-detectbuggood first issuehelp welcomeparser

Metriche repository

Star
 (22.960 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor