typedef, member function and const meat different compilers

From: joe (liesgotold_at_hotmail.com)
Date: 05/13/04


Date: 12 May 2004 15:02:30 -0700

hi,
after reading some articles and faq,
i want to clarify myself what's correct(conform to standard) and
what's not?
or what should be correct but it isn't simply because compilers don't
support.
(first i compiled them with g++3.x. ERR means compiler will bark,
otherwise it does accept it. Then the Comeau C/C++ 4.3.3 comes)

//Q1===================================================//
--g++
typedef const int G(); //cv-qualified to int
typedef int F(); //function type

typedef const F H; //ERR, qualifier applied to function type means
nothing
typedef F const H; //what's it really? i don't know, but compiled with
g++

--Comeau
"ComeauTest.c", line 1: warning: type qualifier on return type is
meaningless
  typedef const int G();
//well, different to what i think. what does std says?
   ^

"ComeauTest.c", line 3: warning: type qualifiers on function types are
ignored
  typedef const F H;
          ^

"ComeauTest.c", line 4: warning: type qualifiers on function types are
ignored
  typedef F const H;
            ^

In strict mode, with -tused, Compile succeeded

//Q2====================================================//
--g++
typedef int (*F2)(); //ok, function pointer "int (*)()"

the following two will be compiled by g++,
but i think they are trivial(or, they shouldn't be compiled?)
typedef const F2 H2; //qualifier applied to function pointer?
typedef F2 const H3; //like the above

--Comeau
In strict mode, with -tused, Compile succeeded

//Q3=======================================================//
--g++
class C;
typedef int (C::*I)(); //a type of "int (C::*)()"
typedef int (C::*J)() const; //const member func, a type of "int
(C::*)() const"

typedef int (C::K)(); //ERR, typedef names can't be class qualified
well, seems reasonable to be ERR, but why?

--Comeau
"ComeauTest.c", line 4: error: qualified name is not allowed
  typedef int (C::K)();
               ^

1 error detected in the compilation of "ComeauTest.c".

In strict mode, with -tused, Compile failed

//Q4==================================================//
--g++
compiled ok, but should they be compiled ok?
class C;
typedef int Q();
typedef Q const C::* R1; //cv-qualified ptr?
typedef Q C::* const R2; //like the above

//--Comeau
"ComeauTest.c", line 3: warning: type qualifiers on function types are
ignored
  typedef Q const C::* R1;
            ^

In strict mode, with -tused, Compile succeeded

//Q5======================================================//
--g++
typedef int M() const; //ERR, invalid qualifier for non-member func
type
why? doesn't it implicitly expresses "int (someclass::*M)() const" and
let us do
the following:

class A
{
        M mf;
};

--Comeau
In strict mode, with -tused, Compile succeeded

//Q6=====================================================//
--g++
class C
{
        typedef int C::M3() const;
        typedef int M2() const; //ERR
        in a class can't we get things done like above?
};

--Comeau
"ComeauTest.c", line 3: error: qualified name is not allowed in member
declaration
          typedef int C::M3() const;
                      ^
//well, different to what i think. what does std says?

1 error detected in the compilation of "ComeauTest.c".

In strict mode, with -tused, Compile failed

i know, it'll be unnecessary and complecated to do things like them
above.
but i will really thank for anyone who give me some hints.
thanks.

        sincerely
                ianz



Relevant Pages

  • Re: Assigning std::sqrt to function pointer
    ... I can't get this seemingly harmless code to compile with Comeau online. ... which it doesn't in "strict mode" in that "web compiler" - but ...
    (comp.lang.cpp)
  • Re: MS Visual Studio 6.0 compile failure
    ... > The following code compiles here in strict mode ... > but it does not compile using MS Visual Studio 6.0. ... Its pretty well known that MSVC++ 6.0 does not compile templates well. ...
    (comp.lang.cpp)
  • Same code problem
    ... compile in VC++ might not compile exactly the same way in the pic compiler. ... typedef long WPARAM; ... typedef long LPARAM; ... HWND hwnd; ...
    (microsoft.public.vc.language)
  • Re: Can one compile khello.cc ?
    ... >upgrade KDE on it. ... >QCString const&, bool, bool)' ... : undefined reference to `QObject::connect(QObject const*, char const*, ... compile to an object file only however, let's test using -c for 'compile ...
    (freebsd-questions)
  • Re: Saving breakpoints
    ... I once considered to add a breakpoint ... Scheme 1: ... Const DebugNewCustomer As Boolean = True ... ' A compile time constant which is also set during testing ...
    (microsoft.public.vb.general.discussion)