commit 448d6065bcfb24d5d5aa904d93a740b552855aa5 Author: Jason Merrill Date: Fri May 8 22:55:30 2015 -0500 libcpp/ * lex.c (lex_string): Add -Wc++11-compat warning. * include/cpplib.h: Add CPP_W_CXX11_COMPAT. (struct cpp_options): Add cpp_warn_cxx11_compat. * init.c (cpp_create_reader): Initialize it. gcc/c-family/ * c.opt (Wc++0x-compat): Set it. diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 3774a89..8f48d84 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -312,7 +312,7 @@ C ObjC Var(warn_cxx_compat) CPP(warn_cxx_operator_names) CppReason(CPP_W_CXX_OPE Warn about C constructs that are not in the common subset of C and C++ Wc++0x-compat -C++ ObjC++ Var(warn_cxx0x_compat) Warning LangEnabledBy(C++ ObjC++,Wall) +C++ ObjC++ Var(warn_cxx0x_compat) Warning LangEnabledBy(C++ ObjC++,Wall) Init(0) CPP(cpp_warn_cxx11_compat) CppReason(CPP_W_CXX11_COMPAT) Deprecated in favor of -Wc++11-compat Wc++11-compat diff --git a/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x4.C b/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x4.C new file mode 100644 index 0000000..c3f0cf5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/warn_cxx0x4.C @@ -0,0 +1,4 @@ +// { dg-options "-Wall" } + +#define FOO "foo" +const char *p = "bar"FOO; // { dg-warning "macro" } diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 5e08014..0152ec8 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -484,6 +484,9 @@ struct cpp_options /* True if warn about differences between C90 and C99. */ signed char cpp_warn_c90_c99_compat; + /* True if warn about differences between C++98 and C++11. */ + bool cpp_warn_cxx11_compat; + /* Dependency generation. */ struct { @@ -960,7 +963,8 @@ enum { CPP_W_LITERAL_SUFFIX, CPP_W_DATE_TIME, CPP_W_PEDANTIC, - CPP_W_C90_C99_COMPAT + CPP_W_C90_C99_COMPAT, + CPP_W_CXX11_COMPAT }; /* Output a diagnostic of some kind. */ diff --git a/libcpp/init.c b/libcpp/init.c index 45a4d13..1ebd709 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -180,6 +180,7 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table, CPP_OPTION (pfile, warn_trigraphs) = 2; CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1; + CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0; CPP_OPTION (pfile, cpp_warn_deprecated) = 1; CPP_OPTION (pfile, cpp_warn_long_long) = 0; CPP_OPTION (pfile, dollars_in_ident) = 1; diff --git a/libcpp/lex.c b/libcpp/lex.c index ac96ff8..c7296a1 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -1905,6 +1905,12 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base) ++cur; } } + else if (CPP_OPTION (pfile, cpp_warn_cxx11_compat) + && is_macro (pfile, cur) + && !pfile->state.skipping) + cpp_warning_with_line (pfile, CPP_W_CXX11_COMPAT, + token->src_loc, 0, "C++11 requires a space " + "between string literal and macro"); pfile->buffer->cur = cur; create_literal (pfile, token, base, cur - base, type);