[libcpp] append "evaluates to 0" for Wundef diagnostic

Prathamesh Kulkarni prathamesh.kulkarni@linaro.org
Fri Aug 19 08:45:00 GMT 2016


Hi David,
This trivial patch appends "evaluates to 0", in Wundef diagnostic,
similar to clang, which prints the following diagnostic for undefined macro:
undef.c:1:5: warning: 'FOO' is not defined, evaluates to 0 [-Wundef]
#if FOO
    ^
Bootstrapped+tested on x86_64-unknown-linux-gnu.
OK to commit ?

Thanks,
Prathamesh
-------------- next part --------------
2016-08-19  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

libcpp/
	* expr.c (eval_token): Append "evaluates to 0" to Wundef diagnostic.

testsuite/
	* gcc.dg/cpp/warn-undef.c: Append "evaluates to 0" to dg-error.
	* gcc.dg/cpp/warn-undef-2.c: Likewise.

diff --git a/gcc/testsuite/gcc.dg/cpp/warn-undef-2.c b/gcc/testsuite/gcc.dg/cpp/warn-undef-2.c
index 15fdde9..e71aeba 100644
--- a/gcc/testsuite/gcc.dg/cpp/warn-undef-2.c
+++ b/gcc/testsuite/gcc.dg/cpp/warn-undef-2.c
@@ -1,5 +1,5 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=undef" }
 /* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#if x  // { dg-error "\"x\" is not defined .-Werror=undef." }
+#if x  // { dg-error "\"x\" is not defined, evaluates to 0 .-Werror=undef." }
 #endif
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-undef.c b/gcc/testsuite/gcc.dg/cpp/warn-undef.c
index dd4524d..2c2c421 100644
--- a/gcc/testsuite/gcc.dg/cpp/warn-undef.c
+++ b/gcc/testsuite/gcc.dg/cpp/warn-undef.c
@@ -1,5 +1,5 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Wundef" }
 
-#if x  // { dg-warning "\"x\" is not defined .-Wundef." }
+#if x  // { dg-warning "\"x\" is not defined, evaluates to 0 .-Wundef." }
 #endif
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 5cdca6f..d32f5a9 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -1073,7 +1073,7 @@ eval_token (cpp_reader *pfile, const cpp_token *token,
 	  result.low = 0;
 	  if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval)
 	    cpp_warning_with_line (pfile, CPP_W_UNDEF, virtual_location, 0,
-				   "\"%s\" is not defined",
+				   "\"%s\" is not defined, evaluates to 0",
 				   NODE_NAME (token->val.node.node));
 	}
       break;


More information about the Gcc-patches mailing list