https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119117

            Bug ID: 119117
           Summary: Implementation of "if declarations" makes instance
                    variables unknown under certain conditions
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: objc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yavor at gnu dot org
  Target Milestone: ---

This was reported as https://bugs.debian.org/1096423 but I'm pretty sure it's a
GCC bug.  There should be no scenario when an instance variable is "unknown" to
the compiler within a method implementation.

Here's a minimal reproducer that doesn't depend on gnustep-base:

$ cat > foo.m <<EOF
#import <objc/Object.h>

@interface Foo : Object
{
  float angle;
}

- (float) angle;
@end

@implementation Foo
- (float) angle
{
  int val = 30;

  if (angle * val > 0.0)
    return 90.0;

  return 0.0;
}
@end

int
main (void)
{
  return 0;
}
EOF

$ make foo LDLIBS=-lobjc
cc     foo.m  -lobjc -o foo
$ touch foo.m
$ make foo LDLIBS=-lobjc OBJC=gcc-15
gcc-15     foo.m  -lobjc -o foo
foo.m: In function ‘-[Foo angle]’:
foo.m:16:7: error: unknown type name ‘angle’
   16 |   if (angle * val > 0.0)
      |       ^~~~~
foo.m:16:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘>’
token
   16 |   if (angle * val > 0.0)
      |                   ^
foo.m:16:7: error: declaration in the controlling expression must have an
initializer
   16 |   if (angle * val > 0.0)
      |       ^~~~~
foo.m:17:17: error: expected ‘)’ before ‘return’
   17 |     return 90.0;
      |                 ^
      |                 )
   18 | 
   19 |   return 0.0;
      |   ~~~~~~         
foo.m:16:6: note: to match this ‘(’
   16 |   if (angle * val > 0.0)
      |      ^
foo.m:20:1: error: expected expression before ‘}’ token
   20 | }
      | ^

$ cc --version
cc (Debian 14.2.0-17) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc-15 --version
gcc-15 (Debian 15-20250220-1) 15.0.1 20250220 (experimental) [master
r15-7637-g94d01a88470]
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This got broken by the C2y if declarations implementation (PR c/117019, commit
440be01).

Reply via email to