C++: more std header hints; filter on C++ dialect (PR c++/84269)
commit0e6feeb8a8241bd54ad7b0e08c08d4e5ae7ab203
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 6 Apr 2018 17:36:33 +0000 (6 17:36 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 6 Apr 2018 17:36:33 +0000 (6 17:36 +0000)
tree2c62c552dbbc7b2b5a90121f7a8243e43fa9d57e
parented63c74f2fa6ea89b7564c605ccb427b89ae9790
C++: more std header hints; filter on C++ dialect (PR c++/84269)

This patch adds more suggestions as per:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84269#c10
some of which need C++14 and C++17, and some of which use headers that
exist in earlier standards.

For example, <memory> exists in C++98, but if the user attempts to
use std::make_shared with -std=c++98, they are suggested to include
<memory>, even if they've already included it.

This patch adds the missing names, and fixes the nonsensical suggestions
by detecting if the name isn't available yet, based on the user's
dialect, and reporting things more intelligently:

t.cc: In function 'void test_make_shared()':
t.cc:5:8: error: 'make_shared' is not a member of 'std'
   std::make_shared<int>();
        ^~~~~~~~~~~
t.cc:5:8: note: 'std::make_shared' is only available from C++11 onwards

gcc/cp/ChangeLog:
PR c++/84269
* name-lookup.c (struct std_name_hint): Move out of
get_std_name_hint; add field "min_dialect".
(get_std_name_hint): Add min_dialect values to all initializers.
Add <any>, <atomic>, <bitset>, <condition_variable>, <functional>,
<future>, <istream>, <iterator>, <ostream>, <mutex>, <optional>,
<shared_mutex>, <string_view>, <thread>, and <variant>.
Add fstream, ifstream, and ofstream to <fstream>.
Add istringstream, ostringstream, and stringstream to <sstream>.
Add basic_string to <string>.
Add tuple_element and tuple_size to <tuple>.
Add declval to <utility>.
Fix ordering of <queue> and <tuple>.
Return a std_name_hint, rather than a const char *.
(get_cxx_dialect_name): New function.
(maybe_suggest_missing_std_header): Detect names that aren't yet
available in the current dialect, and instead of suggesting a
missing #include, warn about the dialect.

gcc/testsuite/ChangeLog:
PR c++/84269
* g++.dg/lookup/missing-std-include-6.C: Move std::array and
std::tuple here since they need C++11.
* g++.dg/lookup/missing-std-include-8.C: New test.
* g++.dg/lookup/missing-std-include.C: Move std::array and
std::tuple test to missing-std-include-6.C to avoid failures
with C++98.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259184 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/missing-std-include-6.C
gcc/testsuite/g++.dg/lookup/missing-std-include-8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/missing-std-include.C