1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/grab_file/grab_file.h>
5 #include <ccan/str/str.h>
18 static const char *can_build(struct manifest *m)
21 return "Safe mode enabled";
25 static struct ccan_file *main_header(struct manifest *m)
29 list_for_each(&m->h_files, f, list) {
30 if (strstarts(f->name, m->basename)
31 && strlen(f->name) == strlen(m->basename) + 2)
34 /* Should not happen: we depend on main_header_compiles */
38 static void check_headers_no_cpp(struct manifest *m,
40 unsigned int *timeleft, struct score *score)
43 char *tmpsrc, *tmpobj, *cmdout;
45 struct ccan_file *mainh = main_header(m);
47 tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname);
48 tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc);
50 /* We don't fail you for this. */
52 fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
54 err(1, "Creating temporary file %s", tmpsrc);
56 contents = talloc_asprintf(tmpsrc,
57 "#define class #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
58 "#define private #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
59 "#define public #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
60 "#define protected #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
61 "#define template #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
62 "#define this #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
63 "#define new #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
64 "#define delete #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
65 "#define friend #DONT_USE_CPLUSPLUS_RESERVED_NAMES\n"
66 "#include <ccan/%s/%s.h>\n",
67 m->basename, m->basename);
68 if (write(fd, contents, strlen(contents)) != strlen(contents))
69 err(1, "writing to temporary file %s", tmpsrc);
72 if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags,
74 score->score = score->total;
76 score->error = talloc_asprintf(score,
77 "Main header file with C++ names:\n%s",
82 struct ccanlint avoids_cpp_reserved = {
83 .key = "avoids_cpp_reserved",
84 .name = "Modules main header compiles without C++ reserved words",
85 .check = check_headers_no_cpp,
87 .needs = "main_header_compiles"
90 REGISTER_TEST(avoids_cpp_reserved);