3

I found this question/answer which describes the use of [[deprecated]] as a C++14 feature to instruct the compiler to warn about the use of deprecated functions.

I tried using this in a simple function within a project - the warning was issued 3 times. I initially thought this might be multiple template instantiations, so I tested a simple program.

[[deprecated]] void doNothing() {}

int main(){
    doNothing();
}

g++ -std=c++14 deprecatedTest.cpp outputs

deprecatedTest.cpp: In function 'int main()':
deprecatedTest.cpp:4:5: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]
     doNothing();
     ^
deprecatedTest.cpp:1:21: note: declared here
 [[deprecated]] void doNothing() {}
                     ^
deprecatedTest.cpp:4:5: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]
     doNothing();
     ^
deprecatedTest.cpp:1:21: note: declared here
 [[deprecated]] void doNothing() {}
                     ^
deprecatedTest.cpp:4:15: warning: 'void doNothing()' is deprecated [-Wdeprecated-declarations]
     doNothing();
               ^
deprecatedTest.cpp:1:21: note: declared here
 [[deprecated]] void doNothing() {}

Is the warning supposed to be printed 3 times? (To get more attention?)

This seems a strange behaviour, but I can't imagine a simpler test.

Community
  • 1
  • 1
chrisb2244
  • 2,940
  • 22
  • 44
  • 1
    Funnily, on g++ 4.9.2 it is printed twice. With clang it is only printed once. – J A Oct 14 '15 at 05:43
  • Seems this is compiler specific (perhaps unsurprisingly?). A (rapidly) deleted answer also highlighted that `clang++` prints only once. I used `g++ v5.2.0` to get 3 outputs - interesting to learn that `v4.9.2` gives it twice. Hopefully there will be an answer explaining why, although I don't know that it will really help anyone (unless it also explains how to get it only once) – chrisb2244 Oct 14 '15 at 05:45
  • 1
    mingw 4.9.2 prints the message twice. Replace `doNothing()` with `auto f = doNothing; f();` and it will be printed only once :) – yzn-pku Oct 14 '15 at 06:14
  • GCC trunk issues two warnings; one at the beginning and one at the end. – T.C. Oct 14 '15 at 08:12
  • @T.C. For the code in the question, or for `auto f = doNothing; f();` ? Either way, good to know. *Edit* My gcc trunk finished compiling - it's twice for the question's code, once for the `auto f = ... ` code. – chrisb2244 Oct 14 '15 at 08:31

1 Answers1

2

This is an obvious Quality of Implementation issue, and not likely to be intentional.

Just raise it on GCC Bugzilla if it's not already there.

OP has raised this on Bugzilla, as suggested. ☺

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055