warning C4227: anachronism used : qualifiers on reference are ignored

So I get that error when I try to do this:

typedef double const (*t_p_training_function)(std::vector<double> const&); // training function pointer type

The MS C++ docs say this about that error:

anachronism used : qualifiers on reference are ignored
Using qualifiers like const or volatile with C++ references is an outdated practice.


Which I don't really understand. Why is using a const qualifier on a reference outdated? It's exactly what I want to do in this case (ie. I want a reference to it and I don't want to modify it).

Should I just pass it as const? Will this have the same effect? Even so, what's wrong with the "reference" just for added clarity?
Last edited on
Looks like a broken diagnostic.

clang++ says
test.cc:4:16: warning: 'const' type qualifier on return type has no effect
      [-Wignored-qualifiers]
typedef double const (*t_p_training_function)(std::vector<double> const&);


g++ says
test.cc:4:73: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
 typedef double const (*t_p_training_function)(std::vector<double> const&);


Intel says
test.cc(4): warning #858: type qualifier on return type is meaningless
  typedef double const (*t_p_training_function)(std::vector<double> const&);
                 ^


Nothing wrong with the reference.
Last edited on
Ah ok, I'll post it over at the MS forums and see what the VC++ devs say..
What version of VC++ are you using? Neither VC++10 nor VC++11 generate an error for that code.

[edit:
On the other hand it is generated as a warning in VC++11 for some slightly different code:

typedef double const (*t_p_training_function)(std::vector<double> & const); where it looks like the intention is for const to modify the reference and not what is referenced.
]
Last edited on
My mistake, the error was cause on the line after that one... Sorry for wasting your time.
Topic archived. No new replies allowed.