Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang: Add support for clang compiler #299

Closed
hab-0 opened this issue Apr 14, 2023 · 3 comments
Closed

Clang: Add support for clang compiler #299

hab-0 opened this issue Apr 14, 2023 · 3 comments
Labels

Comments

@hab-0
Copy link

hab-0 commented Apr 14, 2023

The current generated files (c++) are not compatible with the Clang compiler https://clang.llvm.org/.
e.g:
The following syntax used on the Nunavut generated files is not supported by the Clang compiler:
[[deprecated( string-literal )]]

@pavel-kirienko
Copy link
Member

The syntax you are referring to is standard per C++14. Clang supports C++14 starting with v3.4. Be sure you are using an up-to-date version of the compiler with the correct flags.

@pavel-kirienko pavel-kirienko closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2023
@thirtytwobits
Copy link
Member

Sorry @hab-0 , but can you provide the version of clang you are using? We do compile using clang c++14 as part of our CI so it is generally compatible.

@hab-0
Copy link
Author

hab-0 commented Aug 30, 2023

hi @thirtytwobits ,
Mi clang++ version is:

Ubuntu clang version 14.0.0-1ubuntu1.1
Target: x86_64-pc-linux-gnu

Generator:

nunavut-2.0.9 (serialization was enabled)
c++17

I just created a very simple main program which I try to compile with clang++ with the following options:

clang++ -I . -std=c++17 main.cpp -o main

output:

In file included from main.cpp:2:
./uavcan/node/ExecuteCommand_1_0.hpp:125:7: error: misplaced attributes; expected attributes here
struct Request_1_0 final
^
[[deprecated("uavcan.node.ExecuteCommand.Request.1.0 is reaching the end of its life; there may be a newer version available")]]
./uavcan/node/ExecuteCommand_1_0.hpp:331:7: error: misplaced attributes; expected attributes here
struct Response_1_0 final
^
[[deprecated("uavcan.node.ExecuteCommand.Response.1.0 is reaching the end of its life; there may be a newer version available")]]
2 errors generated.

simple-main.zip

tested with same results also with generator version:

nunavut-2.1.1 (serialization was enabled)
c++17 & c++14

IMO, the problem is the way the generator places the "deprecated" attribute.
According to https://en.cppreference.com/w/c/language/struct the syntax is:

struct attr-spec-seq (optional) name (optional) { struct-declaration-list }

while nunavut is generating:

attr-spec-seq (optional) struct name (optional) { struct-declaration-list }

GCC is more tolerant and just gives you a warning that you can easily suppress:

warning: attribute ignored in declaration of ‘struct uavcan::node::ExecuteCommand::Request_1_0’ [-Wattributes]

Clang seems stricter and so far I did not find the way or an option to compile my application (ignoring or suppressing the error: misplaced attributes)

Just for testing, i modified the file with the syntax as follows:
struct [[deprecated("uavcan.node.ExecuteCommand.Response.1.0 is reaching the end of its life; there may be a newer version available")]] Response_1_0 final

Clang++ does complain and the program is compiled without errors.

Could you please let me know if my findings are correct and the code generator should be modified to generate the struct declaration with the syntax?

struct attr-spec-seq (optional) name (optional) { struct-declaration-list }

beku-epitome added a commit to beku-epitome/nunavut that referenced this issue Nov 3, 2023
beku-epitome added a commit to beku-epitome/nunavut that referenced this issue Nov 3, 2023
beku-epitome added a commit to beku-epitome/nunavut that referenced this issue Nov 3, 2023
beku-epitome added a commit to beku-epitome/nunavut that referenced this issue Nov 3, 2023
thirtytwobits pushed a commit that referenced this issue Nov 3, 2023
#322)

Please review the syntax, I'm no Jinja expert. See #299 for explanation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants