summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp
blob: f76f497393005c6ab42bb9371279d4dfd1cdb922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// RUN: cp %s %t
// RUN: not %clang_cc1 -fixit -Werror -x c++ -std=c++98 %t
// RUN: %clang_cc1 -fsyntax-only -Werror -x c++ -std=c++98 %t
// RUN: cp %s %t
// RUN: not %clang_cc1 -DUSE_BUILTINS -fixit -Werror -x c++ -std=c++98 %t
// RUN: %clang_cc1 -DUSE_BUILTINS -fsyntax-only -Werror -x c++ -std=c++98 %t

extern "C" void *memcpy(void *s1, const void *s2, unsigned n);

#ifdef USE_BUILTINS
# define BUILTIN(f) __builtin_ ## f
#else
# define BUILTIN(f) f
#endif

#define memcpy BUILTIN(memcpy)

int testFixits(int *to, int *from) {
  memcpy(to, from, sizeof(to)); // \
         // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the destination; did you mean to dereference it?}}
  memcpy(0, &from, sizeof(&from)); // \
         // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the source; did you mean to remove the addressof?}}
  return 0;
}
OpenPOWER on IntegriCloud