Skip to content

Possible inconsistency in defined(..) macro calculation #11412

Description

@alanz

Describe the bug

The preprocessor allows testing if a macro is defined, via specific forms (-ifdef, -ifndef) as well as within macro condition evaluation with defined(..).

Special treatment for the built-in macros was introduced in 54dde00, bringing in a test is_macro_defined/2 that checks for a replacement of undefined, and reports false if so, as well as it not being in the macro table.

This is used in the processing of ifdef and ifndef, but not for defined(..), its code is unchanged from when it was introduced (109b1dc)

otp/lib/stdlib/src/epp.erl

Lines 1153 to 1160 in 109b1dc

rewrite_expr({call,_,{atom,_,defined},[N0]}, #epp{macs=Macs}) ->
%% Evaluate defined(Symbol).
N = case N0 of
{var,_,N1} -> N1;
{atom,_,N1} -> N1;
_ -> throw({bad,'if'})
end,
{atom,0,maps:is_key(N, Macs)};

Is this difference expected, or was it overlooked when the others were changed?

Affected versions
It is in current master (

{atom,erl_anno:new(0),maps:is_key(N, Macs)};
)

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugstalledwaiting for input by the Erlang/OTP teamteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions