mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
libstdc++: Make _GLIBCXX_NODISCARD work for C++11 and C++14
The _GLIBCXX_NODISCARD macro only expands to [[__nodiscard__]] for C++17 and later, but all supported compilers will allow us to use that for C++11 and C++14 too. Enable it for those older standards, to give improved diagnostics for users of those older standards. libstdc++-v3/ChangeLog: * include/bits/c++config (_GLIBCXX_NODISCARD): Expand for C++11 and C++14. * testsuite/22_locale/locale/cons/12438.cc: Adjust dg-warning to expect nodiscard warnings for C++11 and C++14 as well. * testsuite/22_locale/locale/operations/2.cc: Likewise. * testsuite/25_algorithms/equal/debug/1_neg.cc: Likewise. * testsuite/25_algorithms/equal/debug/2_neg.cc: Likewise. * testsuite/25_algorithms/equal/debug/3_neg.cc: Likewise. * testsuite/25_algorithms/find_first_of/concept_check_1.cc: Likewise. * testsuite/25_algorithms/is_permutation/2.cc: Likewise. * testsuite/25_algorithms/lexicographical_compare/71545.cc: Likewise. * testsuite/25_algorithms/lower_bound/33613.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/irreflexive.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/25_algorithms/minmax/3.cc: Likewise. * testsuite/25_algorithms/search/78346.cc: Likewise. * testsuite/25_algorithms/search_n/58358.cc: Likewise. * testsuite/25_algorithms/unique/1.cc: Likewise. * testsuite/25_algorithms/unique/11480.cc: Likewise. * testsuite/25_algorithms/upper_bound/33613.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc: Likewise. * testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc: Likewise. * testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc: Likewise. * testsuite/ext/concept_checks.cc: Likewise. * testsuite/ext/is_heap/47709.cc: Likewise. * testsuite/ext/is_sorted/cxx0x.cc: Likewise.
This commit is contained in:
parent
c924a03ae1
commit
e627a941dc
@ -169,7 +169,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Macro to warn about unused results.
|
// Macro to warn about unused results.
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201103L
|
||||||
# define _GLIBCXX_NODISCARD [[__nodiscard__]]
|
# define _GLIBCXX_NODISCARD [[__nodiscard__]]
|
||||||
#else
|
#else
|
||||||
# define _GLIBCXX_NODISCARD
|
# define _GLIBCXX_NODISCARD
|
||||||
|
@ -45,7 +45,7 @@ void test01(int iters)
|
|||||||
locale loc2 = locale("");
|
locale loc2 = locale("");
|
||||||
VERIFY( !has_facet<MyFacet>(loc2) );
|
VERIFY( !has_facet<MyFacet>(loc2) );
|
||||||
|
|
||||||
loc1.combine<MyFacet>(loc2); // { dg-warning "nodiscard" "" { target c++17 } }
|
loc1.combine<MyFacet>(loc2); // { dg-warning "nodiscard" "" { target c++11 } }
|
||||||
VERIFY( false );
|
VERIFY( false );
|
||||||
}
|
}
|
||||||
catch (std::runtime_error&)
|
catch (std::runtime_error&)
|
||||||
|
@ -48,7 +48,7 @@ void test02()
|
|||||||
// Derivation, MF check.
|
// Derivation, MF check.
|
||||||
locale loc_gnu(loc_c, new gnu_collate);
|
locale loc_gnu(loc_c, new gnu_collate);
|
||||||
gnu_count = 0;
|
gnu_count = 0;
|
||||||
loc_gnu(s01, s02); // { dg-warning "nodiscard" "" { target c++17 } }
|
loc_gnu(s01, s02); // { dg-warning "nodiscard" "" { target c++11 } }
|
||||||
VERIFY( gnu_count == 1 );
|
VERIFY( gnu_count == 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ test01()
|
|||||||
std::vector<int> vect;
|
std::vector<int> vect;
|
||||||
vect.push_back(1);
|
vect.push_back(1);
|
||||||
std::equal(vect.end(), vect.begin(), vect.begin());
|
std::equal(vect.end(), vect.begin(), vect.begin());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 29 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 29 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -27,7 +27,7 @@ test01()
|
|||||||
std::vector<int> v1, v2;
|
std::vector<int> v1, v2;
|
||||||
v1.push_back(1);
|
v1.push_back(1);
|
||||||
std::equal(v1.begin(), v1.end(), v2.begin());
|
std::equal(v1.begin(), v1.end(), v2.begin());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 29 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 29 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -33,7 +33,7 @@ test01()
|
|||||||
l2.push_back(2);
|
l2.push_back(2);
|
||||||
|
|
||||||
std::equal(++l1.begin(), l1.end(), ++l2.begin());
|
std::equal(++l1.begin(), l1.end(), ++l2.begin());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 35 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 35 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -37,7 +37,7 @@ class2 b;
|
|||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
std::find_first_of(&a, &a, &b, &b, comp);
|
std::find_first_of(&a, &a, &b, &b, comp);
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 39 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 39 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -103,7 +103,7 @@ void test02()
|
|||||||
int arr[] = { 11, 22, 33 };
|
int arr[] = { 11, 22, 33 };
|
||||||
using namespace std;
|
using namespace std;
|
||||||
is_permutation(begin(arr0), end(arr0), begin(arr), end(arr), thrower);
|
is_permutation(begin(arr0), end(arr0), begin(arr), end(arr), thrower);
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 105 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 105 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -33,5 +33,5 @@ int main()
|
|||||||
X x[1];
|
X x[1];
|
||||||
int i[1];
|
int i[1];
|
||||||
std::lexicographical_compare(x, x+1, i, i+1);
|
std::lexicographical_compare(x, x+1, i, i+1);
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 35 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 35 }
|
||||||
}
|
}
|
||||||
|
@ -33,5 +33,5 @@ bool ab(A, B);
|
|||||||
void test01(A* a, B b)
|
void test01(A* a, B b)
|
||||||
{
|
{
|
||||||
std::lower_bound(a, a, b, ab);
|
std::lower_bound(a, a, b, ab);
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 35 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 35 }
|
||||||
}
|
}
|
||||||
|
@ -44,5 +44,5 @@ void test01()
|
|||||||
{
|
{
|
||||||
A as[] = { 0, 1, 2, 3 };
|
A as[] = { 0, 1, 2, 3 };
|
||||||
std::lower_bound(as, as + 4, 1, A_int_comparer());
|
std::lower_bound(as, as + 4, 1, A_int_comparer());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 46 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 46 }
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ void test01()
|
|||||||
{
|
{
|
||||||
A as[] = { 0, 1, 2, 0, 2, 3 };
|
A as[] = { 0, 1, 2, 0, 2, 3 };
|
||||||
std::lower_bound(as, as + 6, A(1));
|
std::lower_bound(as, as + 6, A(1));
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 38 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 38 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -24,7 +24,7 @@ void test01()
|
|||||||
{
|
{
|
||||||
int as[] = { 0, 1, 0, 2, 3 };
|
int as[] = { 0, 1, 0, 2, 3 };
|
||||||
std::lower_bound(as, as + 5, 1, std::less<int>());
|
std::lower_bound(as, as + 5, 1, std::less<int>());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 26 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 26 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ int compare_counter::count = 0;
|
|||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
std::minmax({1, 2, 3, 4, 5, 6, 7, 8}, compare_counter());
|
std::minmax({1, 2, 3, 4, 5, 6, 7, 8}, compare_counter());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 45 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 45 }
|
||||||
|
|
||||||
// If N is the number of arguments in the minmax function call,
|
// If N is the number of arguments in the minmax function call,
|
||||||
// 25.3.7 specifies that at most 3N/2 comparisons are allowed.
|
// 25.3.7 specifies that at most 3N/2 comparisons are allowed.
|
||||||
|
@ -109,7 +109,7 @@ test01()
|
|||||||
{
|
{
|
||||||
value s[] = { 0, 1, 2, 3, 4, 5 };
|
value s[] = { 0, 1, 2, 3, 4, 5 };
|
||||||
std::search(s, s+6, stashing_iterator(s), stashing_iterator(s+4));
|
std::search(s, s+6, stashing_iterator(s), stashing_iterator(s+4));
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 111 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 111 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -29,7 +29,7 @@ void test01()
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
std::search_n(a.begin(), a.end(), 10, 1,
|
std::search_n(a.begin(), a.end(), 10, 1,
|
||||||
[&count](int t, int u) { ++count; return t == u; });
|
[&count](int t, int u) { ++count; return t == u; });
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 30 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 30 }
|
||||||
VERIFY( count <= 11 );
|
VERIFY( count <= 11 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,6 @@ int main()
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
list<int> menge;
|
list<int> menge;
|
||||||
unique (menge.begin(), menge.end());
|
unique (menge.begin(), menge.end());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 29 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 29 }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ bool compare(int a, int b)
|
|||||||
// libstdc++/11480
|
// libstdc++/11480
|
||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
std::unique(a, a+10, compare); // { dg-warning "ignoring return value" "" { target c++17 } }
|
std::unique(a, a+10, compare); // { dg-warning "ignoring return value" "" { target c++11 } }
|
||||||
VERIFY( compare_count == 9 );
|
VERIFY( compare_count == 9 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,5 +33,5 @@ bool ba(B, A);
|
|||||||
void test01(A* a, B b)
|
void test01(A* a, B b)
|
||||||
{
|
{
|
||||||
std::upper_bound(a, a, b, ba);
|
std::upper_bound(a, a, b, ba);
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 35 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 35 }
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ void test01()
|
|||||||
{
|
{
|
||||||
A as[] = { 0, 2, 1, 3, 4, 5 };
|
A as[] = { 0, 2, 1, 3, 4, 5 };
|
||||||
std::upper_bound(as, as + 6, A(1));
|
std::upper_bound(as, as + 6, A(1));
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 38 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 38 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -24,7 +24,7 @@ void test01()
|
|||||||
{
|
{
|
||||||
int as[] = { 0, 2, 1, 3, 4 };
|
int as[] = { 0, 2, 1, 3, 4 };
|
||||||
std::upper_bound(as, as + 5, 1, std::less<int>());
|
std::upper_bound(as, as + 5, 1, std::less<int>());
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 26 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 26 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ int main()
|
|||||||
{
|
{
|
||||||
__gnu_test::bitmask_operators<std::ios_base::fmtflags>();
|
__gnu_test::bitmask_operators<std::ios_base::fmtflags>();
|
||||||
}
|
}
|
||||||
// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator\\|" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator&" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator\\^" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator~" "" { target c++11 } 0 }
|
||||||
|
@ -27,7 +27,7 @@ int main()
|
|||||||
{
|
{
|
||||||
__gnu_test::bitmask_operators<std::ios_base::iostate>();
|
__gnu_test::bitmask_operators<std::ios_base::iostate>();
|
||||||
}
|
}
|
||||||
// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator\\|" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator&" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator\\^" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator~" "" { target c++11 } 0 }
|
||||||
|
@ -27,7 +27,7 @@ int main()
|
|||||||
{
|
{
|
||||||
__gnu_test::bitmask_operators<std::ios_base::openmode>();
|
__gnu_test::bitmask_operators<std::ios_base::openmode>();
|
||||||
}
|
}
|
||||||
// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator\\|" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator&" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator\\^" "" { target c++11 } 0 }
|
||||||
// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 }
|
// { dg-warning "ignoring return value.*operator~" "" { target c++11 } 0 }
|
||||||
|
@ -73,10 +73,10 @@ test2054( )
|
|||||||
upper_bound(Index.begin(), Index.end(), SearchTerm, aComparison);
|
upper_bound(Index.begin(), Index.end(), SearchTerm, aComparison);
|
||||||
equal_range(Index.begin(), Index.end(), SearchTerm, aComparison);
|
equal_range(Index.begin(), Index.end(), SearchTerm, aComparison);
|
||||||
binary_search(Index.begin(), Index.end(), SearchTerm, aComparison);
|
binary_search(Index.begin(), Index.end(), SearchTerm, aComparison);
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 72 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 72 }
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 73 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 73 }
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 74 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 74 }
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 75 }
|
// { dg-warning "ignoring return value" "" { target c++11 } 75 }
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -24,6 +24,5 @@
|
|||||||
void foo()
|
void foo()
|
||||||
{
|
{
|
||||||
std::vector<int> v;
|
std::vector<int> v;
|
||||||
is_heap(v.begin(), v.end());
|
is_heap(v.begin(), v.end()); // { dg-warning "ignoring return value" }
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 27 }
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,5 @@
|
|||||||
void foo()
|
void foo()
|
||||||
{
|
{
|
||||||
std::vector<int> v;
|
std::vector<int> v;
|
||||||
is_sorted(v.begin(), v.end());
|
is_sorted(v.begin(), v.end()); // { dg-warning "ignoring return value" }
|
||||||
// { dg-warning "ignoring return value" "" { target c++17 } 26 }
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user