g++ test net20.c generates wrong code

Hi All,

I am using the net20.c test case for pointer to member function to compile with clang.

This test generates wrong code when compiled using
‘clang -x c++ …’

https://llvm.org/viewvc/llvm-project/clang-tests/trunk/gcc-4_2-testsuite/src/g%2B%2B.old-deja/g%2B%2B.mike/net20.C?diff_format=c&view=markup&sortby=date

The output it prints is:
define { i32, i32 } @_Z3feev() nounwind {
entry:
%retval = alloca { i32, i32 }, align 4
br label %lab, !dbg !16
lab: ; preds = %lab, %entry
br label %lab, !dbg !18
return: ; No predecessors!
%0 = load { i32, i32 }* %retval, !dbg !19
ret { i32, i32 } %0, !dbg !19
}

Here I see the function is returning ‘{i32,i32}’ i.e. pointer to member function, which is not right, as it should return ‘void’.

Is clang not recognizing this correctly or am I making any mistake ?

Thanks & Regards,
Pankaj

Is clang not recognizing this correctly or am I making any mistake ?

Clang is correct. The function is returning a pointer to a member.
You can check with 'cdecl' when you are unsure what a declaration
means:

$ cdecl -+
Type `help' or `?' for help

explain void (X::* fee ())()

declare fee as function returning pointer to member of class X
function returning void

Dmitri

Thanks a lot.
This information was very helpful.

Regards,
Pankaj