[LLVMbugs] [Bug 21304] New: Illegal source code compiles without error when PCH is enabled

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Oct 17 09:25:02 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21304

            Bug ID: 21304
           Summary: Illegal source code compiles without error when PCH is
                    enabled
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: warren_ristow at playstation.sony.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The test-case below, comprised of "main.cpp" and "foo.h", contains an error
which clang diagnoses well.  But when compiled using PCH, no error is found.
That is, it incorrectly compiles the code that contains the error, as though
there is no error in it.  The PCH-compilation incorrectly completes with
either the '-include <header_file>' style of PCH-compilation, or the
'-include-pch <pch_file>' style of PCH compilation.
________________________________________________

$ cat foo.h
///////////////////////////// "foo.h" ////////////////////////////////
#ifndef FOO_H
#define FOO_H
typedef unsigned int uint32_t;
template< class _Type >
class aTemplateClass
{
  void* m_defaultObject;
public:
  aTemplateClass( uint32_t size ) {}
   virtual void Copy( void* dest, const void* src ) const
  {
    *((_Type*)dest) = *((const _Type*)src);
  }
};
class aNestedClass {
  aNestedClass( aNestedClass && value ) {}
};
class someClass
{
  aNestedClass m_inner;
};
class someOtherClass
{
  aTemplateClass <someClass > *m_tplatePtr;
  someOtherClass()
  {
    m_tplatePtr = new aTemplateClass <someClass > ( sizeof(someClass) );
  }
};
#endif
//////////////////////////////////////////////////////////////////////
$ cat main.cpp
///////////////////////////// "main.cpp" /////////////////////////////
#include "foo.h"

int main() {
  aTemplateClass<int> t(10);
  return 0;
}
//////////////////////////////////////////////////////////////////////
$ clang++ -std=c++11 -c main.cpp  # demonstrate correct diagnosis of the error
In file included from main.cpp:2:
./foo.h:13:21: error: object of type 'someClass' cannot be assigned because its
      copy assignment operator is implicitly deleted
    *((_Type*)dest) = *((const _Type*)src);
                    ^
./foo.h:10:3: note: in instantiation of member function
      'aTemplateClass<someClass>::Copy' requested here
  aTemplateClass( uint32_t size ) {}
  ^
./foo.h:28:23: note: in instantiation of member function
      'aTemplateClass<someClass>::aTemplateClass' requested here
    m_tplatePtr = new aTemplateClass <someClass > ( sizeof(someClass) );
                      ^
./foo.h:21:16: note: copy assignment operator of 'someClass' is implicitly
      deleted because field 'm_inner' has a deleted copy assignment operator
  aNestedClass m_inner;
               ^
./foo.h:17:3: note: copy assignment operator is implicitly deleted because
      'aNestedClass' has a user-declared move constructor
  aNestedClass( aNestedClass && value ) {}
  ^
1 error generated.
$ clang++ -std=c++11 -x c++-header -o foo.h.pch foo.h    # generate PCH file
$ clang++ -std=c++11 -c -include foo.h main.cpp          # use PCH file style 1
$ clang++ -std=c++11 -c -include-pch foo.h.pch main.cpp  # use PCH file style 2
$
________________________________________________

These last two commands:

$ clang++ -std=c++11 -c -include foo.h main.cpp          # use PCH file style 1
$ clang++ -std=c++11 -c -include-pch foo.h.pch main.cpp  # use PCH file style 2

should produce the same error as the non-PCH compilation:

$ clang++ -std=c++11 -c main.cpp  # demonstrate correct diagnosis of the error

but those two "use PCH file" commands did not find the error.

  Tested with:
    clang version 3.6.0 (trunk 219900)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix

Also tried with other targets, and it appears to be target-independent.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141017/c661e5d5/attachment.html>


More information about the llvm-bugs mailing list