https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33911
Elias Pipping <pipping at exherbo dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pipping at exherbo dot org
--- Comment #18 from Elias Pipping <pipping at exherbo dot org> ---
The current status (with gcc 5.3) of these deprecation warnings is quite
surprising: from my point of view there are both false negatives and false
positives. Since clang's behaviour, additionally, differs considerably from
gcc's, it's currently almost impossible to deprecate something in a portable
fashion.
Here's an example. Let's assume I've reimplemented enable_if and want to
deprecated it.
namespace Dune {
template<bool B, class T = void>
struct [[deprecated]] enable_if
{};
template<class T>
struct enable_if<true,T>
{
typedef T type;
};
}
This generates a warning even if enable_if is never used anywhere, simply
through the template specialisation (if I were to remove the specialisation,
the warning would go away):
% g++ -c -std=c++14 test.cc -Wall -Wextra
test.cc:7:10: warning: ‘template<bool B, class T> struct Dune::enable_if’ is
deprecated [-Wdeprecated-declarations]
struct enable_if<true,T>
^
test.cc:3:25: note: declared here
struct [[deprecated]] enable_if
^
%
Clang does not emit a warning here.
Fair enough, maybe I should deprecate specialisations rather than the template.
But this does not work as expected, either. The following code surprisingly
does not emit a single warning:
#include <type_traits>
namespace Dune {
template<bool B, class T = void>
struct enable_if
{};
template<class T>
struct [[deprecated]] enable_if<false,T>
{};
template<class T>
struct [[deprecated]] enable_if<true,T>
{
typedef T type;
};
}
int
main()
{
using newint = Dune::enable_if<std::is_integral<int>::value,int>::type;
newint i = 2;
++i;
}