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 9801 - clang zero-initializing what it should be value-initializing
Summary: clang zero-initializing what it should be value-initializing
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: 2011-04-27 16:22 PDT by Nick Lewycky
Modified: 2011-04-28 13:57 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Lewycky 2011-04-27 16:22:35 PDT
Consider this simple testcase:

  extern "C" { int printf(const char *format, ...); };
  
  struct Test {
    Test() : i(10) {}
    Test(int i) : i(i) {}
    int i;
  private:
    int j;
  };
  
  int main() {
    Test partial[3] = { 1 };
    printf("%d %d %d\n", partial[0].i, partial[1].i, partial[2].i);
  
    Test empty[3] = {};
    printf("%d %d %d\n", empty[0].i, empty[1].i, empty[2].i);
  }

This is a regression; as of r129729 it worked. The program should print "1 10 10" "10 10 10". It currently prints "1 10 10" "0 0 0".

If you shrink the array down to 2 members, the bug goes away. If you remove private members, the bug goes away.
Comment 1 Douglas Gregor 2011-04-27 16:39:23 PDT
Clang r129896 and r129933 made changes in this area.
Comment 2 Douglas Gregor 2011-04-27 16:41:12 PDT
cloned to <rdar://problem/9347552>
Comment 3 Argyrios Kyrtzidis 2011-04-28 13:57:50 PDT
FIxed at r130421, thanks for the report!