Re: [pushed] c/c++: use positive tone in missing header notes [PR84890]

2023-06-18 Thread Richard Sandiford via Gcc-patches
David Malcolm via Gcc-patches  writes:
> Quoting "How a computer should talk to people" (as quoted
> in "Concepts Error Messages for Humans"):
>
> "Various negative tones or actions are unfriendly: being manipulative,
> not giving a second chance, talking down, using fashionable slang,
> blaming. We must not seem to blame the person. We should avoid suggesting
> that the person is inadequate. Phrases like "you forgot" may seem
> harmless, but what if a computer said this to you four or five times in
> two minutes? Anyway, the person may disagree, so why risk offense?"
>
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
> Pushed to trunk as r14-1798-g7474c46cf2d371.

Thanks for doing this.  I agree the new wording is better FWIW.

Not sure if I prefer it for the same reason as above, but IMO impersonal
error messages are actually more friendly (by being neutral and not
questioning the user).

What do you think about doing something similar for “did you mean ...?”
suggestions?  They're useful suggestions to have, but I find the success
rate isn't that high, and asking a direct question when the suggestion
is obviously nonsensical has a slightly confrontational feel.

Not a strong feeling, just a question. :)

Richard

> gcc/c-family/ChangeLog:
>   PR c/84890
>   * known-headers.cc
>   (suggest_missing_header::~suggest_missing_header): Reword note to
>   avoid negative tone of "forgetting".
>
> gcc/cp/ChangeLog:
>   PR c/84890
>   * name-lookup.cc (missing_std_header::~missing_std_header): Reword
>   note to avoid negative tone of "forgetting".
>
> gcc/testsuite/ChangeLog:
>   PR c/84890
>   * g++.dg/cpp2a/srcloc3.C: Update expected message.
>   * g++.dg/lookup/missing-std-include-2.C: Likewise.
>   * g++.dg/lookup/missing-std-include-3.C: Likewise.
>   * g++.dg/lookup/missing-std-include-6.C: Likewise.
>   * g++.dg/lookup/missing-std-include.C: Likewise.
>   * g++.dg/spellcheck-inttypes.C: Likewise.
>   * g++.dg/spellcheck-stdint.C: Likewise.
>   * g++.dg/spellcheck-stdlib.C: Likewise.
>   * gcc.dg/spellcheck-inttypes.c: Likewise.
>   * gcc.dg/spellcheck-stdbool.c: Likewise.
>   * gcc.dg/spellcheck-stdint.c: Likewise.
>   * gcc.dg/spellcheck-stdlib.c: Likewise.
> ---
>  gcc/c-family/known-headers.cc |  2 +-
>  gcc/cp/name-lookup.cc |  2 +-
>  gcc/testsuite/g++.dg/cpp2a/srcloc3.C  |  2 +-
>  .../g++.dg/lookup/missing-std-include-2.C |  8 +--
>  .../g++.dg/lookup/missing-std-include-3.C |  2 +-
>  .../g++.dg/lookup/missing-std-include-6.C |  4 +-
>  .../g++.dg/lookup/missing-std-include.C   | 16 +++---
>  gcc/testsuite/g++.dg/spellcheck-inttypes.C| 54 +--
>  gcc/testsuite/g++.dg/spellcheck-stdint.C  | 40 +++---
>  gcc/testsuite/g++.dg/spellcheck-stdlib.C  | 28 +-
>  gcc/testsuite/gcc.dg/spellcheck-inttypes.c| 52 +-
>  gcc/testsuite/gcc.dg/spellcheck-stdbool.c |  6 +--
>  gcc/testsuite/gcc.dg/spellcheck-stdint.c  | 40 +++---
>  gcc/testsuite/gcc.dg/spellcheck-stdlib.c  | 34 ++--
>  14 files changed, 145 insertions(+), 145 deletions(-)
>
> diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
> index de92cfd6f3c..3484c867ca0 100644
> --- a/gcc/c-family/known-headers.cc
> +++ b/gcc/c-family/known-headers.cc
> @@ -320,6 +320,6 @@ suggest_missing_header::~suggest_missing_header ()
>maybe_add_include_fixit (, m_header_hint, true);
>inform (,
> "%qs is defined in header %qs;"
> -   " did you forget to %<#include %s%>?",
> +   " this is probably fixable by adding %<#include %s%>",
> m_name_str, m_header_hint, m_header_hint);
>  }
> diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
> index eb5c333b5ea..6ac58a35b56 100644
> --- a/gcc/cp/name-lookup.cc
> +++ b/gcc/cp/name-lookup.cc
> @@ -6760,7 +6760,7 @@ class missing_std_header : public deferred_diagnostic
>   maybe_add_include_fixit (, header, true);
>   inform (,
>   "% is defined in header %qs;"
> - " did you forget to %<#include %s%>?",
> + " this is probably fixable by adding %<#include %s%>",
>   m_name_str, header, header);
>}
>  else
> diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc3.C 
> b/gcc/testsuite/g++.dg/cpp2a/srcloc3.C
> index 324e03cd548..c843e07fd4f 100644
> --- a/gcc/testsuite/g++.dg/cpp2a/srcloc3.C
> +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc3.C
> @@ -1,5 +1,5 @@
>  // { dg-do compile { target c++20 } }
>  
>  auto x = __builtin_source_location ();   // { dg-error 
> "'source_location' is not a member of 'std'" }
> -// { dg-message "std::source_location' is defined in header 
> ''; did you forget to '#include '" "" { 
> target *-*-* } .-1 }
> +// { dg-message "std::source_location' is defined in header 
> ''; this is probably fixable by adding '#include 
> '" "" { target 

[pushed] c/c++: use positive tone in missing header notes [PR84890]

2023-06-13 Thread David Malcolm via Gcc-patches
Quoting "How a computer should talk to people" (as quoted
in "Concepts Error Messages for Humans"):

"Various negative tones or actions are unfriendly: being manipulative,
not giving a second chance, talking down, using fashionable slang,
blaming. We must not seem to blame the person. We should avoid suggesting
that the person is inadequate. Phrases like "you forgot" may seem
harmless, but what if a computer said this to you four or five times in
two minutes? Anyway, the person may disagree, so why risk offense?"

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r14-1798-g7474c46cf2d371.

gcc/c-family/ChangeLog:
PR c/84890
* known-headers.cc
(suggest_missing_header::~suggest_missing_header): Reword note to
avoid negative tone of "forgetting".

gcc/cp/ChangeLog:
PR c/84890
* name-lookup.cc (missing_std_header::~missing_std_header): Reword
note to avoid negative tone of "forgetting".

gcc/testsuite/ChangeLog:
PR c/84890
* g++.dg/cpp2a/srcloc3.C: Update expected message.
* g++.dg/lookup/missing-std-include-2.C: Likewise.
* g++.dg/lookup/missing-std-include-3.C: Likewise.
* g++.dg/lookup/missing-std-include-6.C: Likewise.
* g++.dg/lookup/missing-std-include.C: Likewise.
* g++.dg/spellcheck-inttypes.C: Likewise.
* g++.dg/spellcheck-stdint.C: Likewise.
* g++.dg/spellcheck-stdlib.C: Likewise.
* gcc.dg/spellcheck-inttypes.c: Likewise.
* gcc.dg/spellcheck-stdbool.c: Likewise.
* gcc.dg/spellcheck-stdint.c: Likewise.
* gcc.dg/spellcheck-stdlib.c: Likewise.
---
 gcc/c-family/known-headers.cc |  2 +-
 gcc/cp/name-lookup.cc |  2 +-
 gcc/testsuite/g++.dg/cpp2a/srcloc3.C  |  2 +-
 .../g++.dg/lookup/missing-std-include-2.C |  8 +--
 .../g++.dg/lookup/missing-std-include-3.C |  2 +-
 .../g++.dg/lookup/missing-std-include-6.C |  4 +-
 .../g++.dg/lookup/missing-std-include.C   | 16 +++---
 gcc/testsuite/g++.dg/spellcheck-inttypes.C| 54 +--
 gcc/testsuite/g++.dg/spellcheck-stdint.C  | 40 +++---
 gcc/testsuite/g++.dg/spellcheck-stdlib.C  | 28 +-
 gcc/testsuite/gcc.dg/spellcheck-inttypes.c| 52 +-
 gcc/testsuite/gcc.dg/spellcheck-stdbool.c |  6 +--
 gcc/testsuite/gcc.dg/spellcheck-stdint.c  | 40 +++---
 gcc/testsuite/gcc.dg/spellcheck-stdlib.c  | 34 ++--
 14 files changed, 145 insertions(+), 145 deletions(-)

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index de92cfd6f3c..3484c867ca0 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -320,6 +320,6 @@ suggest_missing_header::~suggest_missing_header ()
   maybe_add_include_fixit (, m_header_hint, true);
   inform (,
  "%qs is defined in header %qs;"
- " did you forget to %<#include %s%>?",
+ " this is probably fixable by adding %<#include %s%>",
  m_name_str, m_header_hint, m_header_hint);
 }
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index eb5c333b5ea..6ac58a35b56 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -6760,7 +6760,7 @@ class missing_std_header : public deferred_diagnostic
maybe_add_include_fixit (, header, true);
inform (,
"% is defined in header %qs;"
-   " did you forget to %<#include %s%>?",
+   " this is probably fixable by adding %<#include %s%>",
m_name_str, header, header);
   }
 else
diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc3.C 
b/gcc/testsuite/g++.dg/cpp2a/srcloc3.C
index 324e03cd548..c843e07fd4f 100644
--- a/gcc/testsuite/g++.dg/cpp2a/srcloc3.C
+++ b/gcc/testsuite/g++.dg/cpp2a/srcloc3.C
@@ -1,5 +1,5 @@
 // { dg-do compile { target c++20 } }
 
 auto x = __builtin_source_location (); // { dg-error "'source_location' is not 
a member of 'std'" }
-// { dg-message "std::source_location' is defined in header 
''; did you forget to '#include '" "" { 
target *-*-* } .-1 }
+// { dg-message "std::source_location' is defined in header 
''; this is probably fixable by adding '#include 
'" "" { target *-*-* } .-1 }
 // { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-2 }
diff --git a/gcc/testsuite/g++.dg/lookup/missing-std-include-2.C 
b/gcc/testsuite/g++.dg/lookup/missing-std-include-2.C
index 51c604a9f1e..fa1ec0b0e66 100644
--- a/gcc/testsuite/g++.dg/lookup/missing-std-include-2.C
+++ b/gcc/testsuite/g++.dg/lookup/missing-std-include-2.C
@@ -16,10 +16,10 @@ namespace std
 void test (void)
 {
   std::string s ("hello world"); // { dg-error ".string. is not a member of 
.std." }
-  // { dg-message ".std::string. is defined in header ..; did you 
forget to .#include .?" "" { target *-*-* } .-1 }
+  // { dg-message ".std::string. is defined in header ..; this is 
probably fixable by adding .#include ."