Commit 5c240f4d by David Malcolm Committed by David Malcolm

PR c/69993: improvements to wording of -Wmisleading-indentation

gcc/c-family/ChangeLog:
	PR c/69993
	* c-indentation.c (warn_for_misleading_indentation): Rewrite the
	diagnostic text, reversing the order of the warning and note so
	that they appear in source order.

gcc/testsuite/ChangeLog:
	PR c/69993
	* c-c++-common/Wmisleading-indentation-3.c: New test, based on
	Wmisleading-indentation.c.
	* c-c++-common/Wmisleading-indentation.c: Update thoughout to
	reflect change to diagnostic text and order of messages.
	* gcc.dg/plugin/location-overflow-test-2.c: Likewise.

From-SVN: r234403
parent 80f6631b
2016-03-22 David Malcolm <dmalcolm@redhat.com>
PR c/69993
* c-indentation.c (warn_for_misleading_indentation): Rewrite the
diagnostic text, reversing the order of the warning and note so
that they appear in source order.
2016-03-17 Marek Polacek <polacek@redhat.com>
PR c/69407
......
......@@ -602,10 +602,12 @@ warn_for_misleading_indentation (const token_indent_info &guard_tinfo,
body_tinfo,
next_tinfo))
{
if (warning_at (next_tinfo.location, OPT_Wmisleading_indentation,
"statement is indented as if it were guarded by..."))
inform (guard_tinfo.location,
"...this %qs clause, but it is not",
if (warning_at (guard_tinfo.location, OPT_Wmisleading_indentation,
"this %qs clause does not guard...",
guard_tinfo_to_string (guard_tinfo)))
inform (next_tinfo.location,
("...this statement, but the latter is misleadingly indented"
" as if it is guarded by the %qs"),
guard_tinfo_to_string (guard_tinfo));
}
}
2016-03-22 David Malcolm <dmalcolm@redhat.com>
PR c/69993
* c-c++-common/Wmisleading-indentation-3.c: New test, based on
Wmisleading-indentation.c.
* c-c++-common/Wmisleading-indentation.c: Update thoughout to
reflect change to diagnostic text and order of messages.
* gcc.dg/plugin/location-overflow-test-2.c: Likewise.
2016-03-22 David Edelsohn <dje.gcc@gmail.com>
* g++.dg/ext/java-3.C: Don't compile on AIX.
......
/* Verify -Wmisleading-indentation with source-printing.
This is a subset of Wmisleading-indentation.c. */
/* { dg-options "-Wmisleading-indentation -fdiagnostics-show-caret" } */
/* { dg-do compile } */
extern int foo (int);
extern int bar (int, int);
extern int flagA;
extern int flagB;
extern int flagC;
extern int flagD;
void
fn_5 (double *a, double *b, double *sum, double *prod)
{
int i = 0;
for (i = 0; i < 10; i++) /* { dg-warning "3: this 'for' clause does not guard..." } */
sum[i] = a[i] * b[i];
prod[i] = a[i] * b[i]; /* { dg-message "5: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'for'" } */
/* { dg-begin-multiline-output "" }
for (i = 0; i < 10; i++)
^~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
prod[i] = a[i] * b[i];
^~~~
{ dg-end-multiline-output "" } */
}
/* Based on CVE-2014-1266 aka "goto fail" */
int fn_6 (int a, int b, int c)
{
int err;
/* ... */
if ((err = foo (a)) != 0)
goto fail;
if ((err = foo (b)) != 0) /* { dg-message "2: this 'if' clause does not guard..." } */
goto fail;
goto fail; /* { dg-message "3: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'" } */
if ((err = foo (c)) != 0)
goto fail;
/* ... */
/* { dg-begin-multiline-output "" }
if ((err = foo (b)) != 0)
^~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
goto fail;
^~~~
{ dg-end-multiline-output "" } */
fail:
return err;
}
#define FOR_EACH(VAR, START, STOP) \
for ((VAR) = (START); (VAR) < (STOP); (VAR++)) /* { dg-warning "3: this 'for' clause does not guard..." } */
void fn_14 (void)
{
int i;
FOR_EACH (i, 0, 10) /* { dg-message "in expansion of macro .FOR_EACH." } */
foo (i);
bar (i, i); /* { dg-message "5: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'for'" } */
/* { dg-begin-multiline-output "" }
for ((VAR) = (START); (VAR) < (STOP); (VAR++))
^
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
FOR_EACH (i, 0, 10)
^~~~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
bar (i, i);
^~~
{ dg-end-multiline-output "" } */
}
#undef FOR_EACH
......@@ -20,7 +20,7 @@ int
fn_1 (int flag)
{
int foo = 4, bar = 5;
if (flag) foo = 3; bar = 2; /* { dg-warning "indented" } */
if (flag) foo = 3; bar = 2; /* { dg-warning "this .if." } */
return foo * bar;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment