Bug 30343 - False positive: allocating zero-element array
Summary: False positive: allocating zero-element array
Status: RESOLVED DUPLICATE of bug 4210
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-01 18:47 UTC by Gregor Jasny
Modified: 2007-01-01 19:03 UTC (History)
6 users (show)

See Also:
Host: i486-linux-gnu
Target: i486-linux-gnu
Build: gcc version 4.2.0 20061217 (prerelease) (Debian 4.2-20061217-1)
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gregor Jasny 2007-01-01 18:47:05 UTC
Hi,

The following code produces a false positive warning "allocating zero-element array".

template <class T, int size = 0> class Array
{
public:
  Array() {
    if (size) {
      new T[size];
    }
  }
};

void foo() {
  Array<int> bar;
}

the new command is guarded by a if(size). So allocating a zero size array is impossible. It would be really nice if gcc could check for this condition, also.

Thanks,
Gregor
Comment 1 Andrew Pinski 2007-01-01 19:03:13 UTC

*** This bug has been marked as a duplicate of 4210 ***