Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
>
V1115. Function annotated with the 'pur…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C++)
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu Contents

V1115. Function annotated with the 'pure' attribute has side effects.

Oct 03 2024

The analyzer has detected a function annotated as pure, but it is not.

You can annotate functions in the following ways:

A function is pure if it meets the following requirements:

  • It has no side effects. A function should not alter the state of the program outside its own context. This means it should not modify objects with static storage duration (local and global) or modify non-constant objects via pointers/references passed to the function.
  • The function behavior is deterministic. A function must always return the same result for the same set of inputs.

Here are the most common cases in which a function purity is violated:

  • using variables with static storage duration in any form;
  • calling a function that has side effects;
  • using constructs that cause side effects (for example, 'new', 'delete');
  • using parameters as lvalue references or pointers to non-constants;
  • writing to/reading from streams (e.g. 'std::cout', 'std:: fstream', etc.).

Take a look at the following example of an impure function annotated as pure:

[[gnu::pure]] void foo() 
{
  int *x = new int;
  ....
}

The 'foo' function is annotated in the code using the 'gnu::pure' attribute but allocates dynamic memory and violates the "no side effects" requirement.

To fix this, either remove the 'pure' attribute or modify the function as follows:

[[gnu::pure]] void foo()
{
  int x;
  ....
}