On 31 March 2016 at 21:10, Daniel Gutson wrote:
> Hi,
>
>   many times we copy code snippets from sources that change the
> Unicode quotation marks ( “ ” ) rather than " ". For example
>
>          const std::string a_string(“Hello”);
>
> That line looks innocent but causes gcc to say
>
> xxxxx.cpp:4:1: error: stray ‘\342’ in program
>  const std::string a_string(“Hello”);
>  ^
>
> misleading the poor programmer with such error message and wrong
> column. A quick Google search says there are 171,000 matches for "
> error: stray ‘\342’ in program" which may show that this is a very
> common issue.

I have hit that problem several times and would welcome a smarter diagnostic.


> I want to know if there is consensus to one of these solutions that I
> can implement:
>
>    * improve the error message for the case of the Unicode quotes such
> as adding "(seems Unicode quotes where used)"

IMHO this would be better.

It doesn't actually help fix the code, it only helps identify the
problem, but this is usually only a problem for small pieces of code
copied from a webpage, so fixing it isn't a huge task.

>    * add a flag for a GNU extension so Unicode quotes are treated as
> regular quotes

That could change the meaning of valid code unless it was careful to
ignore fancy quotes inside string literals,  e.g. we wouldn't want to
change the meaning of:

const std::string a_string(" “Hello” ");

Reply via email to