public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14459] New: Regression 3.4 : Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore.
@ 2004-03-06 15:57 carlo at gcc dot gnu dot org
  2004-03-06 21:51 ` [Bug c++/14459] [3.4/3.5? regression] " bangerth at dealii dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: carlo at gcc dot gnu dot org @ 2004-03-06 15:57 UTC (permalink / raw)
  To: gcc-bugs

The following compiles with 3.3.3, it doesn't compile with 3.4.

~/c++/g++.bugs/bug18>cat test.cc
// Deliberate errors so we can see what the type of 'T' is.
template<typename T> float f1(T) { return T(); }
template<typename T> float f2(T) { return T(); }
template<typename T> float f3(T) { return T(); }

static int (*S_main)(int, char**, char**);

int main(int, char**, char**)
{
  // This works:
  f1((__typeof__(S_main))(main));

  // This works:
  typedef __typeof__(S_main) type_of_S_main;
  f2(type_of_S_main(main));

  // This doesn't anymore:
  f3(__typeof__(S_main)(main));
}


~/c++/g++.bugs/bug18>g++-3.3.3 -Wall -c test.cc
test.cc: In function `float f1(T) [with T = int (*)(int, char**, char**)]':
test.cc:11:   instantiated from here
test.cc:2: error: cannot convert `int (*)(int, char**, char**)' to `float' in
   return
test.cc: In function `float f2(T) [with T = int (*)(int, char**, char**)]':
test.cc:15:   instantiated from here
test.cc:3: error: cannot convert `int (*)(int, char**, char**)' to `float' in
   return
test.cc: In function `float f3(T) [with T = int (*)(int, char**, char**)]':
test.cc:18:   instantiated from here
test.cc:4: error: cannot convert `int (*)(int, char**, char**)' to `float' in
   return


~/c++/g++.bugs/bug18>g++-cvs-3.4 -Wall -c test.cc
test.cc: In function `int main(int, char**, char**)':
test.cc:18: error: invalid conversion from `int (*)(int, char**, char**)' to `int'
test.cc:18: error: too few arguments to function
test.cc:18: error: expected primary-expression before "typeof"
test.cc: In function `float f1(T) [with T = int (*)(int, char**, char**)]':
test.cc:11:   instantiated from here
test.cc:2: error: cannot convert `int (*)(int, char**, char**)' to `float' in return
test.cc: In function `float f2(T) [with T = int (*)(int, char**, char**)]':
test.cc:15:   instantiated from here
test.cc:3: error: cannot convert `int (*)(int, char**, char**)' to `float' in return


For some reason 3.4 thinks that  __typeof__(S_main)(main) has
type 'int' thus.

-- 
           Summary: Regression 3.4 : Assignment of cast of __typeof__ of
                    function pointer not treated as function pointer
                    anymore.
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carlo at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14459


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/14459] [3.4/3.5? regression] Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore.
  2004-03-06 15:57 [Bug c++/14459] New: Regression 3.4 : Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore carlo at gcc dot gnu dot org
@ 2004-03-06 21:51 ` bangerth at dealii dot org
  2004-04-07  2:50 ` pinskia at gcc dot gnu dot org
  2004-05-24  1:55 ` mmitchel at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: bangerth at dealii dot org @ 2004-03-06 21:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-03-06 21:51 -------
Confirmed, though I believe this may be a parser problem. Take this example instead: 
-------------------- 
void g(...); 
void foo(int) 
{ 
  g((__typeof__(&foo))(foo)); 
  g(__typeof__(&foo)(foo)); 
} 
------------------ 
where we get: 
 
tmp/g> ~/bin/gcc-3.3/bin/c++ -c x.cc 
tmp/g> /workspace/bangerth/build-gcc-3.4/gcc-install/bin/c++ -c x.cc 
x.cc: In function `void foo(int)': 
x.cc:5: error: invalid conversion from `void (*)(int)' to `int' 
x.cc:5: error: expected primary-expression before "typeof" 
 
So the first line succeeds because the parser sees an argument to g() of the form 
(type)(value), i.e. a C-style type cast. In the second line, we have a C++-style initializer 
of the form type(value). The parser gets this wrong, or at least differently than before. 
 
I'm not sure whether we have any specification that says how __typeof__ is supposed to work. 
I could imagine, it works as 
  __typeof__ expr 
and the parser tries to take 
  expr = &foo(foo) 
and gets confused because the address of foo is not the right type of argument to call 
foo() and take the address of the return value. This is supported by looking at this testcase: 
-------------------- 
void g(...); 
void foo() 
{ 
  g(__typeof__(&foo)(foo)); 
} 
------------------- 
where we get 
x.cc: In function `void foo()': 
x.cc:4: error: too many arguments to function 
x.cc:4: error: expected primary-expression before "typeof" 
 
The first line indicates that we try to call foo() with an argument, which shouldn't work since 
foo doesn't take any arguments. 
 
Do we have someone who can tell us how __typeof__ is supposed to work? 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |3.4.0
      Known to work|                            |3.3.3
            Summary|Regression 3.4 : Assignment |[3.4/3.5? regression]
                   |of cast of __typeof__ of    |Assignment of cast of
                   |function pointer not treated|__typeof__ of function
                   |as function pointer anymore.|pointer not treated as
                   |                            |function pointer anymore.


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14459


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/14459] [3.4/3.5? regression] Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore.
  2004-03-06 15:57 [Bug c++/14459] New: Regression 3.4 : Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore carlo at gcc dot gnu dot org
  2004-03-06 21:51 ` [Bug c++/14459] [3.4/3.5? regression] " bangerth at dealii dot org
@ 2004-04-07  2:50 ` pinskia at gcc dot gnu dot org
  2004-05-24  1:55 ` mmitchel at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-07  2:50 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
   Target Milestone|---                         |3.4.1


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14459


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/14459] [3.4/3.5? regression] Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore.
  2004-03-06 15:57 [Bug c++/14459] New: Regression 3.4 : Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore carlo at gcc dot gnu dot org
  2004-03-06 21:51 ` [Bug c++/14459] [3.4/3.5? regression] " bangerth at dealii dot org
  2004-04-07  2:50 ` pinskia at gcc dot gnu dot org
@ 2004-05-24  1:55 ` mmitchel at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-05-24  1:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2004-05-23 18:16 -------
This is not a defect.

The GCC manual says that the syntax of "typeof" is like "sizeof".  That means
that there are two operand forms, either "( type-id )" or "unary-expression".

In this case, 

  g(__typeof__(&foo)(foo));

the operand is not the "( type-id )" case, so it must be the "unary-expression"
case.  A "postfix-expression" is a kind of "unary-expression", which means that
the "(foo)" is treated as an argument to "(&foo)".  An analogous example with
"sizeof" is:

  int *p;
  sizeof(p)[p]

which will yield an error message, while:

  (sizeof(p))[p]

will work.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14459


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-05-23 18:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-06 15:57 [Bug c++/14459] New: Regression 3.4 : Assignment of cast of __typeof__ of function pointer not treated as function pointer anymore carlo at gcc dot gnu dot org
2004-03-06 21:51 ` [Bug c++/14459] [3.4/3.5? regression] " bangerth at dealii dot org
2004-04-07  2:50 ` pinskia at gcc dot gnu dot org
2004-05-24  1:55 ` mmitchel at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).