Consider: const int* get_foo() {return nullptr;}
The suggested fix should be static const int* get_foo(){}
and not const static int* get_foo(){}
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
14252 | Could you add tests for the following cases? I'm not sure the implementation will work. // Two spaces between 'const' and 'struct'. const struct MyStruct get_struct() ... const /*comment*/ struct MyStruct get_struct() ... #define MY_CONST const MY_CONST struct MyStruct get_struct() ... I think a better way would be to check the token that comes before the type name, and if that token is 'const', then adjust the source location -- otherwise insert the 'static' keyword where we used to insert it in the past. |
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
14252 | Done. |
clang/lib/Lex/Lexer.cpp | ||
---|---|---|
1302 ↗ | (On Diff #269627) | I'm concerned about putting this API into Lexer, given this implementation. It is not a precise general-purpose implementation, it can have false negatives (for example, if the const token is formed through macros, or token pasting or whatnot), and it can have false positives (if the 'const' token is actually a macro that expands to something else). I'd suggest to define this function as a local lambda right where it is used or inline it completely into findBeginLoc. |
clang/test/Sema/warn-missing-prototypes.c | ||
57 | Why not return (void*)0;? | |
62 | Did you mean to return a pointer to MyStruct? The top-level const is not meaningful. | |
63 | Extra indentation? Please make it consistent with other tests. | |
71 | cost => const | |
98 | "Since we can't easily understand what MY_CONST means while preparing the diagnostic, the fix-it suggests to add 'static' in a non-idiomatic place." |
clang/test/Sema/warn-missing-prototypes.c | ||
---|---|---|
62 | No, I actually intended to test the top-level const. Though not being meaningful, it's still syntactically correct. |
Could you add tests for the following cases? I'm not sure the implementation will work.
I think a better way would be to check the token that comes before the type name, and if that token is 'const', then adjust the source location -- otherwise insert the 'static' keyword where we used to insert it in the past.