Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

type qualifier on return type is meaningless

malat
Beginner
2,081 Views
Hello,

So far icc gave really good results. It has by default some nice flags (-Wshadow from gcc ...). But on the other hand there is one warning I don't quite follow:

warning #858: type qualifier on return type is meaningless

Here is an example to reproduce(*). If you uncomment those lines and try to compile it with gcc:

g++ -ansi -pedantic -Wall foo.cpp

It does not produce any warnings. Furthermore I do believe that const can be usefull for instance in this case. Is this correct or do I misunderstood something ?

Thanks
Mathieu

(*)
#include >iostream<

const void foo()
{
std::cout "foo" std::endl;
}

int main()
{
//void (*p) () = &foo //const is usefull in this case
//p();

return 0;
}
0 Kudos
6 Replies
Max_L
Employee
2,081 Views
Hi,

Please note that 'const' in you example is just related to function return type. And yes, it is really meaning less to use cv-qualifiers (const/volatile) for r-value return types, because you cannot modify them, especially it is useless for void return type.

Why do you fill const is useful in your example, what do you really want to get?

Max
0 Kudos
malat
Beginner
2,081 Views
Max

Thanks for answering. Looking back at my question I realize it doesn't make much sense. so I just remove the const from my project.

But still, to be very picky, I think that 'void', eventhough it is not an object type, is still a type. Thus it can be cv-qualified (3.9.3).

And also another example :

template
const R foo(const ARG) {
...
}

foo(5);

What would icc undersand from that ?

Thanks again
Mathieu
0 Kudos
Max_L
Employee
2,081 Views
Mathieu, Your example is incorrect, because you cannot automatically deduce template parameter value from return type: test02.cpp(8): error: no instance of function template "foo" matches the argumen t list argument types are: (int) foo( 0 ); ^ You can call only foo< void >( 0 ), explicitly specifying type for return value. It compiled without that warning, it is reasonable because off in generic case it is make sense to use const to return value. e.g. operator + () for some overloaded type like complex, you should use const: const complex operator + ( complex const &, complex const&) ; to repeat behavior of the plain types, because you cannot write int a, b; (a+b)=0; But without const in operator + declaration for complex you can write such code. Hope, I've correctly understand and answered your question, have I? Thanks, Max
0 Kudos
Max_L
Employee
2,081 Views
Mathieu,

Your example is incorrect, because you cannot automatically deduce template parameter value from return type:

test02.cpp(8): error: no instance of function template "foo" matches the argument list argument types are: (int)
foo( 0 );
^

You can call only foo< void >( 0 ), explicitly specifying type for return value. It compiled without that warning, it is reasonable because off in generic case it is make sense to use const to return value. e.g. operator + () for some overloaded type like complex, you should use const:

const complex operator + ( complex const &, complex const&);

to repeat behavior of the plain types, because you cannot write

int a, b; (a+b)=0;

But without const in operator + declaration for complex you can write such code.

Hope, I've correctly understand and answered your question, have I?

Thanks,
Max

Message Edited by Max_Locktyukhin on 08-23-2004 07:23 AM

0 Kudos
malat
Beginner
2,081 Views
Max,

Ok you are right, I was wrong. Thanks for taking the time to answer me.
0 Kudos
Max_L
Employee
2,081 Views
Mathieu,

You was not wrong, you asked the question! :)

Please, don't hesitate to ask questions here in future, we really want to make this forum useful for our compiler users.

Thank you,
Max

Message Edited by Max_Locktyukhin on 08-24-2004 12:22 AM

0 Kudos
Reply