4. Given $a^{3}+b^{3}+3 a b=1$. Then the value of $a+b$ is ( ).
(A) 1
(B) -2
(C) 1 or -2
(D) None of the above
4. C .

Let $a+b=x$. Then
$$
\begin{array}{l}
(a+b)^{3}=a^{3}+b^{3}+3 a b(a+b) \\
\Rightarrow x^{3}-3 a b x+3 a b=1 \\
\Rightarrow x^{3}-1-3 a b(x-1)=0 \\
\Rightarrow(x-1)\left(x^{2}+x+1-3 a b\right)=0
\end{array}
$$
$$
\begin{array}{l}
\Rightarrow x=1 \text { or } x^{2}+x+1=3 a b \\
\Rightarrow a+b=1 \text { or } x^{2}+x+1=3 a b .
\end{array}
$$

When $x^{2}+x+1=3 a b$, we have
$$
\begin{array}{l}
(a+b)^{2}+(a+b)+a^{3}+b^{3}+3 a b=3 a b \\
\Rightarrow(a+b)^{2}+(a+b)+(a+b)\left(a^{2}+b^{2}-a b\right)=0 \\
\Rightarrow(a+b)\left(a^{2}+b^{2}-a b+a+b+1\right)=0 \\
\Rightarrow a+b=0 \text { or } a^{2}+b^{2}-a b+a+b+1=0 .
\end{array}
$$

When $a+b=0$, we have
$$
\begin{array}{l}
a=-b \Rightarrow a^{3}=-b^{3} \\
\Rightarrow a^{3}+b^{3}+3 a b=1 \Rightarrow 3 a^{2}=-1 .
\end{array}
$$

Thus, $a+b=0$ does not hold.
When $a^{2}+b^{2}-a b+a+b+1=0$, we have
$$
\begin{array}{l}
2\left(a^{2}+b^{2}-a b+a+b+1\right)=0 \\
\Rightarrow(a-b)^{2}+(a+1)^{2}+(b+1)^{2}=0
\end{array}
$$
$\Rightarrow a=b=-1 \Rightarrow a+b=-2$.
Therefore, $a+b=1$ or -2.