highlightjs/highlight.js

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

已关闭

#3,673 创建于 2022年12月8日

 (6 条评论) (0 个反应) (0 位负责人)JavaScript (3,497 个派生)batch import
auto-detectbuggood first issuehelp welcomeparser

仓库指标

星标
 (22,960 个星标)
PR 合并指标
 (平均合并 6分钟) (30 天内合并 2 个 PR)

描述

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

贡献者指南