Clang error: the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions) (err_attribute_vecreturn_only_pod_record)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)
Type Error
Category Semantic Issue
Internal Id err_attribute_vecreturn_only_pod_record
Internal Message the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)
Regular Expression (?:error|fatal error)\: the vecreturn attribute can only be used on a POD \(plain old data\) class or structure \(i\.e\. no virtual functions\)
First Commit 2010-09-18 9a587aaaa9e7 Add more error checking to attribute vecreturn

Description

The error is issued by the Clang compiler when the vecreturn attribute is applied to a class or structure that does not meet the criteria of being Plain Old Data (POD). The vecreturn attribute is designed to be used only on types that are POD, which essentially means that the type is compatible with C types and does not contain any C++ specific features like virtual functions, inheritance, or constructors and destructors that do custom work. A class or structure is considered not to be POD if it contains virtual functions, as these introduce a level of complexity that is incompatible with the intended use of the vecreturn attribute. The constraint exists because the vecreturn attribute aims to optimize the return of complex values from functions in ways that are only safe and predictable for POD types. Applying this attribute to non-POD types could lead to undefined behavior or other errors; thus, the compiler checks for POD compliance and issues this error message if the criteria are not met.  
AI Generated

Example

In the following example, a struct named S is defined with a single member function f, which is a virtual function. This struct is attempted to be marked with the vecreturn attribute. The presence of a virtual function in the struct makes it ineligible to be considered Plain Old Data (POD). As a result, the Clang compiler produces an error message indicating that the vecreturn attribute can only be applied to POD types, which do not include structures or classes with virtual functions. This demonstrates the compiler's check for POD compliance when the vecreturn attribute is used, ensuring that it is only applied to compatible types to prevent undefined behavior.  
AI Generated


Flags -xc++

[Try out in Compiler Explorer]

Source
struct S { virtual void f() {} } __attribute__((vecreturn));
// virtual function
Compiler Output
<source>:1:49: error: the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)


Clang Internals (17.0.6)

Git Commit Message

Add more error checking to attribute vecreturn

llvm-svn: 114251

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Sema/SemaDeclAttr.cpp (line 2299)

// PS3 PPU-specific.
static void handleVecReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
  // ...
  if (!cast<CXXRecordDecl>(R)->isPOD()) {
    S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_pod_record);

Triggered in Clang Tests

This section lists all internal Clang test cases that trigger the diagnostic.

clang/test/Parser/cxx-altivec.cpp

  • clang/test/Parser/cxx-altivec.cpp:224:18: error: the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)