[Bug c++/77922] Bogus suggestion: ‘constexpr’ does not name a type; did you mean ‘constexpr’?

dmalcolm at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Oct 11 13:49:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77922

--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #0)
> constexpr int a = 1;
> with -std=c++98 gives
> pr.C:1:1: error: ‘constexpr’ does not name a type; did you mean ‘constexpr’?
>  constexpr int a = 1;
>  ^~~~~~~~~
>  constexpr
> pr.C:1:1: note: C++11 ‘constexpr’ only available with -std=c++11 or
> -std=gnu++11
> 
> I'd say we should just not print the bogus "did you mean" if the identifier
> fuzzy matching found is the same as the one used originally.  Or not add
> constexpr into the suggestions in this case because it is not C++98?

If we accidentally add the goal string to the list of candidate strings when
building the list, then we'll get the goal string back, with an edit distance
of 0, and it will always be a bad suggestion.

So we probably should put a check for this case into
get_best_meaningful_candidate.  It seems to me that doing so could mask an
error: we've mispopulated the candidate list; the bad suggestion could still be
offered if someone typed something similar (e.g. "consexpr" or somesuch).  But
at least if they then try the suggestion, they'll get the:
  note: C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11

So I think there are three parts to fixing this:
(a) fix get_best_meaningful_candidate to detect the distance == 0 case and
return NULL
(b) filter the identifiers based on "-std" when figuring out the candidate
strings
(c) update the note's text as noted in comment #2.


More information about the Gcc-bugs mailing list