https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63807

            Bug ID: 63807
           Summary: -Wvarargs doesn't warn when last argument has type
                    that causes undefined behaviour
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

The standard says in 18.10 [support.runtime]:

  If the parameter parmN is of a reference type, or of a type that is not
  compatible with the type that results when passing an argument for which
  there is no parameter, the behavior is undefined.

Testcase:

#include <stdarg.h>

void f(int& i, ...)
{
  va_list a;
  va_start(a, i);
  va_end(a);
}

int main()
{
  int i=0;
  f(i, 1);
}

G++ produces no diagnostic.


Compiling with EDG says:

"va.cc", line 6: error: incorrect use of va_start

Compiling with Clang says:

va.cc:6:15: warning: 'va_start' has undefined behavior with reference types
[-Wvarargs]

There is no error from ubsan using either G++ or Clang.

Reply via email to