Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strange behavior of static asserts #585

Closed
x539 opened this issue Feb 27, 2014 · 5 comments
Closed

strange behavior of static asserts #585

x539 opened this issue Feb 27, 2014 · 5 comments

Comments

@x539
Copy link

x539 commented Feb 27, 2014

I noticed the following strange behavior, when playing around with new platform support for ldc.
/the druntime uses the pattern below for "static assert(false, "platform not supported");/

test.d:

version (abc)
  alias int fooBar;
else
  static assert(false, "bad configuration");

version (bug) {

  fooBar abc;

} else {

  int functionA() {
     fooBar abc;
  }

}
ldc2 -c -d-version=bug test.d

gives:

test.d(7): Error: undefined identifier fooBar

expected output is (as it is for the no-bug version)

test.d(4): Error: static assert  "bad configuration"
@schuetzm
Copy link

This happens with DMD master, too.

@redstar
Copy link
Member

redstar commented Apr 14, 2014

@schuetzm Do you know the bugzilly entry?

@schuetzm
Copy link

No, sorry. I just compiled and ran it on DMD.

redstar pushed a commit that referenced this issue Sep 27, 2014
@9rnsr
Copy link

9rnsr commented Mar 23, 2016

At least there's no spec for the evaluation timing of static assert, so there's no issue about that the semantic failure of invalid variable declaration fooBar abc; is detected first.

More precise information: In dmd frontend, senamtic analysis is separated to three sub-stages - semantic1, semantic2, and semantic3. They're normally invoked in the order of their numbers.
On a variable declaration, its type analysis will be done in semantic1. On the other hands, static assert evaluation is done in semantic2. With the case code, the module level semantic1 stage fails on fooBar abc;, then semantic2 is not invoked.

@kinke
Copy link
Member

kinke commented Mar 23, 2016

Thanks for digging out this old issue. I'm closing it as it has nothing to do with LDC itself.

@kinke kinke closed this as completed Mar 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants