mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
ImportC: add __attribute__((pure)) (#15145)
This commit is contained in:
parent
c8a88f599a
commit
72f6eff8b8
5 changed files with 24 additions and 2 deletions
|
@ -2893,6 +2893,8 @@ final class CParser(AST) : Parser!AST
|
|||
auto parameterList = cparseParameterList();
|
||||
const lkg = specifier.mod & MOD.x__stdcall ? LINK.windows : linkage;
|
||||
StorageClass stc = specifier._nothrow ? STC.nothrow_ : 0;
|
||||
if (specifier._pure)
|
||||
stc |= STC.pure_;
|
||||
AST.Type tf = new AST.TypeFunction(parameterList, t, lkg, stc);
|
||||
// tf = tf.addSTC(storageClass); // TODO
|
||||
insertTx(ts, tf, t); // ts -> ... -> tf -> t
|
||||
|
@ -3539,6 +3541,11 @@ final class CParser(AST) : Parser!AST
|
|||
specifier._nothrow = true;
|
||||
nextToken();
|
||||
}
|
||||
else if (token.ident == Id._pure)
|
||||
{
|
||||
specifier._pure = true;
|
||||
nextToken();
|
||||
}
|
||||
else if (token.ident == Id.vector_size)
|
||||
{
|
||||
nextToken();
|
||||
|
@ -4944,6 +4951,7 @@ final class CParser(AST) : Parser!AST
|
|||
bool noreturn; /// noreturn attribute
|
||||
bool naked; /// naked attribute
|
||||
bool _nothrow; /// nothrow attribute
|
||||
bool _pure; /// pure attribute
|
||||
bool dllimport; /// dllimport attribute
|
||||
bool dllexport; /// dllexport attribute
|
||||
bool _deprecated; /// deprecated attribute
|
||||
|
|
|
@ -8896,6 +8896,7 @@ struct Id final
|
|||
static Identifier* show;
|
||||
static Identifier* push;
|
||||
static Identifier* pop;
|
||||
static Identifier* _pure;
|
||||
static Identifier* define;
|
||||
static Identifier* undef;
|
||||
static void initialize();
|
||||
|
|
|
@ -377,8 +377,8 @@ extern (C++) class FuncDeclaration : Declaration
|
|||
extern (D) this(const ref Loc loc, const ref Loc endloc, Identifier ident, StorageClass storage_class, Type type, bool noreturn = false)
|
||||
{
|
||||
super(loc, ident);
|
||||
//printf("FuncDeclaration(id = '%s', type = %p)\n", id.toChars(), type);
|
||||
//printf("storage_class = x%x\n", storage_class);
|
||||
//.printf("FuncDeclaration(id = '%s', type = %s)\n", ident.toChars(), type.toChars());
|
||||
//.printf("storage_class = x%llx\n", storage_class);
|
||||
this.storage_class = storage_class;
|
||||
this.type = type;
|
||||
if (type)
|
||||
|
|
|
@ -546,6 +546,7 @@ immutable Msgtable[] msgtable =
|
|||
{ "show" },
|
||||
{ "push" },
|
||||
{ "pop" },
|
||||
{ "_pure", "pure" },
|
||||
{ "define" },
|
||||
{ "undef" },
|
||||
];
|
||||
|
|
12
compiler/test/fail_compilation/attrpure.i
Normal file
12
compiler/test/fail_compilation/attrpure.i
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/attrpure.i(11): Error: `pure` function `attrpure.pureAsSnow` cannot call impure function `attrpure.impure`
|
||||
---
|
||||
*/
|
||||
|
||||
void impure();
|
||||
|
||||
__attribute__((pure)) void pureAsSnow()
|
||||
{
|
||||
impure();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue