forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++: provide macro used-before-defined hint (PR c++/72786)
This patch uses the name_hint/deferred_diagnostic to provide a message in the C++ frontend if a macro is used before it is defined e.g.: test.c:6:24: error: expected ';' at end of member declaration virtual void clone() const OVERRIDE { } ^~~~~ ; test.c:6:30: error: 'OVERRIDE' does not name a type virtual void clone() const OVERRIDE { } ^~~~~~~~ test.c:6:30: note: the macro 'OVERRIDE' had not yet been defined test.c:15:0: note: it was later defined here #define OVERRIDE override It's possible to do it from the C++ frontend as tokenization happens up-front (and hence the macro already exists when the above is parsed); I attempted to do it from the C frontend, but because the C frontend only tokenizes on-demand during parsing, the macro isn't known about until later. gcc/cp/ChangeLog: PR c++/72786 * name-lookup.c (class macro_use_before_def): New class. (lookup_name_fuzzy): Detect macro that were used before being defined, and report them as such. gcc/ChangeLog: PR c++/72786 * spellcheck.h (best_match::blithely_get_best_candidate): New accessor. gcc/testsuite/ChangeLog: PR c++/72786 * g++.dg/spellcheck-macro-ordering-2.C: New test case. * g++.dg/spellcheck-macro-ordering.C: Add dg-message directives for macro used-before-defined. libcpp/ChangeLog: PR c++/72786 * include/cpplib.h (cpp_macro_definition_location): New decl. * macro.c (cpp_macro_definition): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254978 138bc75d-0d04-0410-961f-82ee72b054a4
- Loading branch information
dmalcolm
committed
Nov 21, 2017
1 parent
69eab56
commit dbfb2c4
Showing
10 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
2017-11-20 David Malcolm <[email protected]> | ||
|
||
PR c++/72786 | ||
* spellcheck.h (best_match::blithely_get_best_candidate): New | ||
accessor. | ||
|
||
2017-11-20 Jakub Jelinek <[email protected]> | ||
|
||
* config/i386/i386.c (parse_mtune_ctrl_str): Start diagnostics | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
2017-11-20 David Malcolm <[email protected]> | ||
|
||
PR c++/72786 | ||
* name-lookup.c (class macro_use_before_def): New class. | ||
(lookup_name_fuzzy): Detect macro that were used before being | ||
defined, and report them as such. | ||
|
||
2017-11-20 Jason Merrill <[email protected]> | ||
|
||
* decl2.c (constrain_class_visibility): Don't warn about artificial | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
2017-11-20 David Malcolm <[email protected]> | ||
|
||
PR c++/72786 | ||
* g++.dg/spellcheck-macro-ordering-2.C: New test case. | ||
* g++.dg/spellcheck-macro-ordering.C: Add dg-message directives | ||
for macro used-before-defined. | ||
|
||
2017-11-20 Steve Ellcey <[email protected]> | ||
|
||
PR target/81356 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// PR c++/72786 | ||
|
||
/* Example of undeffed macro. */ | ||
|
||
#define OVERRIDE override | ||
|
||
#undef OVERRIDE | ||
|
||
class DocTargetDriver { | ||
virtual void clone() const OVERRIDE { } // { dg-line usage } | ||
/* Offering "OVERRIDE" as a spelling suggestion for "OVERRIDE" would be | ||
nonsensical. */ | ||
// { dg-bogus "did you mean" "" { target *-*-* } usage } | ||
// { dg-error "expected .;. at end of member declaration" "" { target *-*-* } usage } | ||
// { dg-error ".OVERRIDE. does not name a type" "" { target *-*-* } usage } | ||
// { dg-bogus "macro" "" { target *-*-* } usage } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
2017-11-20 David Malcolm <[email protected]> | ||
|
||
PR c++/72786 | ||
* include/cpplib.h (cpp_macro_definition_location): New decl. | ||
* macro.c (cpp_macro_definition): New function. | ||
|
||
2017-11-13 Tom Tromey <[email protected]> | ||
|
||
* pch.c (cpp_read_state): Set n__VA_OPT__. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters