[cfe-dev] FunctionDecl question
mats petersson via cfe-dev
cfe-dev at lists.llvm.org
Tue Jul 18 05:37:12 PDT 2017
Is this C++ or C?
In C++, both declarations represent the same thing (a function with no
arguments), so there shouldn't be any meaningful difference in the AST.
In C the foo() means "unspecified arguments", foo(void) means "no
arguments".
For C++, I guess you could try to find the location in the source of the
parenthesis [the AST has "sourcelocation", I think - yes, it does:
https://stackoverflow.com/questions/11083066/getting-the-source-behind-clangs-ast
], and see if there is a "void" between there - of course, that could get
interesting if someone does:
#define V void
void foo(V) { ... }
or
#define NO_ARGS (void)
void foo NO_ARGS { ... }
[and many other variations, that one could come up with, I'm sure]
but for the simple case where there are no macros involved, it should work.
--
Mats
On 18 July 2017 at 13:19, Frank Redeker via cfe-dev <cfe-dev at lists.llvm.org>
wrote:
> > On 18 July 2017 at 10:33, Frank Redeker via cfe-dev
> > <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
> >
> > Hello list,
> >
> > is there is an easy way to distinguish if a function is declared as
> >
> > void foo (void);
> > or
> > void foo ();
> >
> > The reason I'm asking is that I use an ASTVisitor to generate stub
> > functions. But the compiler that I use reports an error when the
> > prototype is declared with (void) but the implementation not.
> >
>
> > Am 18.07.2017 um 11:41 schrieb Alex L:
> > You can look at it's type and check if it has a function prototype (i.e.
> > it has parameters or (void), see the FunctionProtoType class), e.g.
> > FD->getType()->isFunctionProtoType() .
> >
>
> Hallo Alex,
>
> thanks for the hint. But the FD->getType()->isFunctionProtoType()
> returns true in both cases and FD->getType()->isFunctionNoProtoType()
> returns false in both cases.
>
> So is there any other way to distinguish the declarations?
>
>
> Frank
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170718/86398778/attachment.html>
More information about the cfe-dev
mailing list