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

            Bug ID: 84165
           Summary: #define strlen asdf affects calls to asdf
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manuel.rigger at jku dot at
  Target Milestone: ---

Hi,

I have a file asdf.h with the following content:

#define strlen asdf

I have another file test.c with the following content:

#include <stdio.h>
#include <string.h>
#include <stdio.h>

unsigned long asdf(const char* s) {
    printf("asdf gets called with argument %s.", s);
    return 1234;
}

int main(void) {
    asdf("asdf");
    return 0;
}

After compiling with clang -include asdf.h test.c -o test I get the following
output:

test.c:11:5: warning: ignoring return value of function declared with pure
attribute [-Wunused-value]
    asdf("asdf");
    ^~~~ ~~~~~~
1 warning generated.

Executing the executable does not print anything.

I would have expected that the executable calls asdf(), but it seems that
asdf() was expected to be strlen(), which does not have any side effects, and
was thus deleted. Is this the correct behavior? Are defines bidirectional?

GCC version: gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0

Reply via email to