Skip to content

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

Open
@GuillaumeDua

Description

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

Metadata

Assignees

No one assigned

    Labels

    auto-detectIssue with auto detection of language typebuggood first issueShould be easier for first time contributorshelp welcomeCould use help from communityparser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions