https://bugs.llvm.org/show_bug.cgi?id=40713

            Bug ID: 40713
           Summary: Poor diagnostics when accidentally using an #include
                    in a macro
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

I ran into this problem today:

$ cat test.cc
#define DECLARE_CONTEXTUAL_VARIABLE(a, b)  /* ... */


DECLARE_CONTEXTUAL_VARIABLE(a, 1;   // Missing a ')'!
DECLARE_CONTEXTUAL_VARIABLE(b, 1);
DECLARE_CONTEXTUAL_VARIABLE(c, 1);
DECLARE_CONTEXTUAL_VARIABLE(d, 1);

#include "a.h"
#include "b.h"
#include "c.h"
#include "d.h"
#include "e.h"
#include "f.h"
#include "g.h"
#include "h.h"
#include "i.h"
#include "j.h"
#include "k.h"
#include "l.h"
#include "m.h"
#include "n.h"
#include "o.h"
#include "p.h"
#include "q.h"
#include "r.h"
#include "s.h"
Nicos-MacBook-Pro:llvm-project thakis$ clang -c test.cc
test.cc:9:2: error: embedding a #include directive within macro arguments is
not supported
#include "a.h"
 ^
test.cc:10:2: error: embedding a #include directive within macro arguments is
not supported
#include "b.h"
 ^
test.cc:11:2: error: embedding a #include directive within macro arguments is
not supported
#include "c.h"
 ^
test.cc:12:2: error: embedding a #include directive within macro arguments is
not supported
#include "d.h"
 ^
test.cc:13:2: error: embedding a #include directive within macro arguments is
not supported
#include "e.h"
 ^
test.cc:14:2: error: embedding a #include directive within macro arguments is
not supported
#include "f.h"
 ^
test.cc:15:2: error: embedding a #include directive within macro arguments is
not supported
#include "g.h"
 ^
test.cc:16:2: error: embedding a #include directive within macro arguments is
not supported
#include "h.h"
 ^
test.cc:17:2: error: embedding a #include directive within macro arguments is
not supported
#include "i.h"
 ^
test.cc:18:2: error: embedding a #include directive within macro arguments is
not supported
#include "j.h"
 ^
test.cc:19:2: error: embedding a #include directive within macro arguments is
not supported
#include "k.h"
 ^
test.cc:20:2: error: embedding a #include directive within macro arguments is
not supported
#include "l.h"
 ^
test.cc:21:2: error: embedding a #include directive within macro arguments is
not supported
#include "m.h"
 ^
test.cc:22:2: error: embedding a #include directive within macro arguments is
not supported
#include "n.h"
 ^
test.cc:23:2: error: embedding a #include directive within macro arguments is
not supported
#include "o.h"
 ^
test.cc:24:2: error: embedding a #include directive within macro arguments is
not supported
#include "p.h"
 ^
test.cc:25:2: error: embedding a #include directive within macro arguments is
not supported
#include "q.h"
 ^
test.cc:26:2: error: embedding a #include directive within macro arguments is
not supported
#include "r.h"
 ^
test.cc:27:2: error: embedding a #include directive within macro arguments is
not supported
#include "s.h"
 ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.




This was in a large file and from the errors it was not at all clear where the
missing ) was. I ended up locally patching up clang, since I didn't think of
increasing -ferror-limit to an astronomical number (now that I know what the
problem was I realize that eventually a



test.cc:4:1: error: unterminated function-like macro invocation
DECLARE_CONTEXTUAL_VARIABLE(a, 1;   // Missing a ')'!
^
test.cc:1:9: note: macro 'DECLARE_CONTEXTUAL_VARIABLE' defined here
#define DECLARE_CONTEXTUAL_VARIABLE(a, b)  /* ... */



diag will appear, but that was cut off in my case.)


I think it'd be good if clang could print a note pointing to the active macro
call with the "embedding..." diag. I'll make a patch for that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to