Ville is going to prepare something for the new -Wclass-memacess and
-Wcatch-value warnings. Suggestions for other gotchas to document are
welcome.
Committed to CVS.
Index: htdocs/gcc-8/porting_to.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-8/porting_to.html,v
retrieving revision 1.3
diff -u -r1.3 porting_to.html
--- htdocs/gcc-8/porting_to.html 23 Jan 2018 14:16:49 - 1.3
+++ htdocs/gcc-8/porting_to.html 25 Apr 2018 15:42:29 -
@@ -30,6 +30,131 @@
C++ language issues
+-Wreturn-type is enabled by default
+
+
+ G++ now assumes that control never reaches the end of a non-void function
+ (i.e. without reaching a return statement). This means that
+ you should always pay attention to -Wreturn-type warnings,
+ as they indicate code that can misbehave when optimized.
+
+
+
+ To tell the compiler that control can never reach the end of a function
+ (e.g. because all callers enforce its preconditions) you can suppress
+ -Wreturn-type warnings by adding
+ __builtin_unreachable:
+
+
+ char signchar(int i) // precondition: i != 0
+ {
+if (i 0)
+ return '+';
+else if (i 0)
+ return '-';
+__builtin_unreachable();
+ }
+
+
+
+ Because -Wreturn-type is now enabled by default, G++ will
+ warn if main is declared with an implicit int
+ return type (which is non-standard but allowed by GCC). To avoid the
+ warning simply add a return type to main, which makes the
+ code more portable anyway.
+
+
+Stricter rules when using templates
+
+
+ G++ now diagnoses even more cases of ill-formed templates which can never
+ be instantiated (in addition to
+ the stricter
+ rules in GCC 7).
+ The following example will now be diagnosed by G++ because the type of
+ BT::a does not depend on T and so the
+ function BT::f is ill-formed for every possible
+ instantiation of the template:
+
+
+ class A { };
+ template typename T struct B {
+bool f() const { return a; }
+A a;
+ };
+
+
+
+In member function 'bool BT::f() const':
+error: cannot convert 'const A' to 'bool' in return
+ bool f() const { return a; }
+ ^
+
+
+
+ Ill-formed template code that has never been tested and can never be
+ instantiated should be fixed or removed.
+
+
+Changes to alignof results
+
+
+ The alignof operator has been changed to return the minimum
+ alignment required by the target ABI, instead of the preferred alignment
+ (consistent with _Alignof in C).
+
+
+
+ Previously the following assertions could fail on 32-bit x86 but will now
+ pass. GCC's preferred alignment for standalone variables of type
+ double or long long is 8 bytes, but the minimum
+ alignment required by the ABI (and so used for non-static data members)
+ is 4 bytes:
+
+
+
+ struct D { double val; };
+ static_assert(alignof(D) == alignof(double), "...");
+ struct L { long long val; };
+ static_assert(alignof(L) == alignof(long long), "...");
+
+
+
+ Code which uses alignof to obtain the preferred
+ alignment can use __alignof__ instead.
+
+
+Associative containers check the comparison function
+
+
+ The associative containers (std::map,
+ std::multimap, std::set, and
+ std::multiset) now use static assertions to check that their
+ comparison functions support the necessary operations.
+ In C++17 mode this includes enforcing that the function can be called
+ when const-qualified:
+
+
+ struct Cmp {
+bool operator()(int l, int r) /* not const */ { return l r; }
+ };
+ std::setint, Cmp s;
+
+
+In member function 'bool BT::f() const':
+error: static assertion failed: comparison object must be invocable as const
+ static_assert(is_invocable_vconst _Compare, const _Key, const _Key,
+ ^
+ bool f() const { return a; }
+ ^
+
+
+This can be fixed by adding const to the call operator:
+
+ struct Cmp {
+bool operator()(int l, int r) const { return l r; }
+ };
+
Fortran language issues
Index: htdocs/gcc-8/porting_to.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-8/porting_to.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- htdocs/gcc-8/porting_to.html 25 Apr 2018 15:44:23 - 1.4
+++ htdocs/gcc-8/porting_to.html 25 Apr 2018 15:46:36 - 1.5
@@ -124,7 +124,7 @@
alignment can use __alignof__ instead.
-Associative containers check the comparison function
+Associative containers check the comparison function
The associative containers (std::map,