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

Compiler incorrectly warns about pure volatile reads #9053

Open
scabug opened this issue Dec 19, 2014 · 4 comments
Open

Compiler incorrectly warns about pure volatile reads #9053

scabug opened this issue Dec 19, 2014 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Dec 19, 2014

Scala 2.11 warns about pure expressions in statement position. This warning is incorrect for volatile reads. A volatile read has the side-effect of inserting a memory read barrier (which must not be optimized away by the JIT even when the actual read is unnecessary and can be removed).

[warn] /Users/szeiger/code/slick/src/main/scala/scala/slick/backend/DatabaseComponent.scala:190: a pure expression does nothing in statement position; you may be omitting necessary parentheses
[warn]             ctx.sync
[warn]                 ^
@scabug
Copy link
Author

scabug commented Dec 19, 2014

Imported From: https://issues.scala-lang.org/browse/SI-9053?orig=1
Reporter: @szeiger
Affected Versions: 2.11.2, 2.11.4

@scabug
Copy link
Author

scabug commented Dec 19, 2014

@szeiger said:
Checking the bytecode, the volatile reads are still generated (as they should be). It's just the warning that is wrong.

@scabug
Copy link
Author

scabug commented Jan 8, 2015

@scabug
Copy link
Author

scabug commented Jan 16, 2015

@retronym said:
Workaround if you want to silence to warning:

  def volatileRead() = ctx.sync
  volatileRead()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants