This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter


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

           Summary: Type 'void' is treated differently if used as return
                    value or as parameter
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: fredrik.hederstierna@securitas-direct.com


It is valid to return a void-function, or cast a variable to void, from a
void-function.

This makes some sense, in particular in C++ since we might have a template, and
we would like to put 'void' as type in this C++ template.

But then maybe it should also be allowed to put 'void' as inparameter to a
void-function, but then compiler warns about too many arguments.

void.c: In function âmainâ:
void.c:16: error: too many arguments to function âf1â
void.c:17: error: too many arguments to function âf2â

Somehow it would be more 'aligned' to have function-return-values and
function-in-parameters work the same way, so that template-alike-constructions,
or similar pure C macro/preprocessor constructions, could work the same
perhaps?

void f1(void)
{
  return (void)0; //OK
}

void f2(void)
{
  return f1(); //OK
}

int main(void)
{
  f1();        //OK
  f2();        //OK
  f1((void)0); //ERROR
  f2(f1());    //ERROR
  return 0;   
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]