From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] coccinelle to rescue for "C++11 requires a space between literal and string macro"
Date: Tue, 28 Aug 2018 15:19:08 -0700 (PDT) [thread overview]
Message-ID: <alpine.DEB.2.21.1808281514290.2555@hadrien> (raw)
In-Reply-To: <DM3PR14MB0766042ACA4CECA31C33FF29800A0@DM3PR14MB0766.namprd14.prod.outlook.com>
On Tue, 28 Aug 2018, Felix Blyakher wrote:
> Hello coccinelle experts,
>
> I'm working with the legacy code and with newish gcc 7.3 hit the following warning:
>
> warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
> #define PADARG64 "0x%016"QUAD"x"
> ^
>
> where QUAD is a platform dependent string, thus the macro.
>
> The string concatenation works in C OK for this code, though, gcc rightfully complains
> about required space and wants it to be:
>
> #define PADARG64 "0x%016" QUAD "x"
>
> The code like this is sprinkled across huge code base, mostly in printf-like statements,
> and some in defines like above to be used in printf-like statements.
>
> I'd like to use coccinelle to change the code globally.
> I was trying something like (I know it may have false positive, just need to get something for starter):
>
>
> @@
> Identifier I;
> @@
>
> -"I"
> +" I "
Coccinelle doesn't interpret things inside strings, except format
directives. Also, identifier shouldn't be capitalized.
What you want is:
@@
constant char[] c;
@@
- c
+ c
When Coccinelle adds the string back, it will pretty print it properly.
If you want to see a diff in the output, put --force-diff on the command
line. Normally Coccinelle doesn't print a diff when there are only
whitespace changes.
This will work on every string in your code. If you don't want this, then
you can put:
constant char[] c : script:python { check c };
where check is some python code you write under
@initialize:python@
@@
def check ...
to check whether it is a string with multiple pieces. Note that the c
that check received will have the spaces already, so it won't be possible
to tell if the string is actually missing spaces. But you can distinguish
strings in multiple pieces from string that are atomic.
Let me know if anything is not clear.
julia
next prev parent reply other threads:[~2018-08-28 22:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-28 21:18 [Cocci] coccinelle to rescue for "C++11 requires a space between literal and string macro" Felix Blyakher
2018-08-28 22:19 ` Julia Lawall [this message]
2018-08-29 16:25 ` Felix Blyakher
2018-08-29 16:32 ` Julia Lawall
[not found] ` <c78ab16d-c26b-9a90-1989-c5a91e276e67@users.sourceforge.net>
2018-08-30 16:51 ` [Cocci] Checking support for the analysis of preprocessor definitions Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.21.1808281514290.2555@hadrien \
--to=julia.lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.