LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 7789 - Failure to detect "jump to case label crosses initialization"
Summary: Failure to detect "jump to case label crosses initialization"
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-02 07:49 PDT by bugzilla-clang
Modified: 2010-08-02 18:33 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments
source code to reproduce bug (113 bytes, text/x-c++src)
2010-08-02 07:49 PDT, bugzilla-clang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bugzilla-clang 2010-08-02 07:49:06 PDT
Created attachment 5308 [details]
source code to reproduce bug

Hi!

When compiling a 'switch' in which a 'case' contains an initialized variable (see example) Clang does so without complaining. g++ on the other hand produces an error "jump to case label crosses initialization".

I'm not really sure which is correct. According to this thread (http://www.velocityreviews.com/forums/t282021-error-jump-to-case-label.html) and the explanation for it's behavior, g++ is correct.

[code]
switch (a) {
  //...
  case 1:
  int a = 1;
  break;
  case 2:
  //...
}
[/code]

g++ output for attached file:
> clang-bug.cpp: In function ‘int main()’:
> clang-bug.cpp:10: error: jump to case label
> clang-bug.cpp:7: error:   crosses initialization of ‘int a’

clang++ output for attached file:
-
(compiles without error/warning)


My system:
Linux VirtUbuntu 2.6.32-24-generic #38-Ubuntu SMP Mon Jul 5 09:22:14 UTC 2010 i686 GNU/Linux

clang version 2.8 (trunk 109579)
Target: i386-pc-linux-gnu
Thread model: posix
Comment 1 John McCall 2010-08-02 18:33:39 PDT
Fixed in r110082.