elliotchance / c2go

⚖️ A tool for transpiling C to Go.
MIT License
2.06k stars 151 forks source link

warn_unused_result extra field not handled by regex #861

Closed kroppt closed 3 years ago

kroppt commented 4 years ago

error:

~/code/c2go $ go test -tags=integration ./...
panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) <(?P<position>.*)>(?P<inherited> Inherited)?( warn_unused_result)?[\s]*$
0x55c2df4f93b8 <col:53> warn_unused_result ""

goroutine 74 [running]:
github.com/elliotchance/c2go/ast.groupsFromRegex(0xc00040c070, 0x61, 0xc000805987, 0x2d, 0x14)
        /home/user/code/c2go/ast/ast.go:310 +0x360
github.com/elliotchance/c2go/ast.parseWarnUnusedResultAttr(0xc000805987, 0x2d, 0x14)
        /home/user/code/c2go/ast/warn_unused_result_attr.go:13 +0x62
github.com/elliotchance/c2go/ast.Parse(0xc000805972, 0x42, 0x705495, 0x5)
        /home/user/code/c2go/ast/ast.go:286 +0x2fb2
github.com/elliotchance/c2go.convertLinesToNodes(0xc000feb9d0, 0x1b9e, 0x52da, 0x0, 0x0, 0x0)
        /home/user/code/c2go/main.go:89 +0x1a6
github.com/elliotchance/c2go.convertLinesToNodesParallel.func1.2(0xc0000280c0, 0xc00011a020, 0xc000feb9d0, 0x1b9e, 0x52da, 0x0)
        /home/user/code/c2go/main.go:121 +0x53
created by github.com/elliotchance/c2go.convertLinesToNodesParallel.func1
        /home/user/code/c2go/main.go:119 +0x1b5

clang:

~ $ clang --version
clang version 10.0.0
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/10/bin

The following text was added to the warn_usued_result attribute in clang 10: "A string literal may optionally be provided to the attribute, which will be reproduced in any resulting diagnostics. Redeclarations using different forms of the attribute (with or without the string literal or with different string literal contents) are allowed. If there are redeclarations of the entity with differing string literals, it is unspecified which one will be used by Clang in any resulting diagnostics.

"Additionally, discarded temporaries resulting from a call to a constructor marked with [[nodiscard]] or a constructor of a type marked [[nodiscard]] will also diagnose. This also applies to type conversions that use the annotated [[nodiscard]] constructor or result in an annotated type." https://releases.llvm.org/10.0.0/tools/clang/docs/AttributeReference.html#nodiscard-warn-unused-result