By <a href="https://en.wikipedia.org/wiki/Chern%E2%80%93Weil_homomorphism">Chern-Weil theory</a>, the real <a href="https://en.wikipedia.org/wiki/Pontryagin_class">Pontryagin classes</a> $p_k \in H^{4k}(X, \mathbb{R})$ of a real vector bundle $V$ on a smooth manifold $X$ are determined by the curvature form of any connection on that bundle; in particular, if the curvature vanishes, then so do all of the $p_k$. Hence if any of the $p_k$ don't vanish, then $V$ does not admit a flat connection. (Note that all of the $p_k$ vanish if $\dim X \le 3$; Milnor's result regarding the case $\dim X = 2$ requires more difficult tools.) 

If $V$ is taken to be the tangent bundle of $X$, then the first case where this happens is when $\dim X = 4$, where $p_1 \in H^4(X, \mathbb{R})$. If $X$ is closed and orientable then $p_1$ is nonzero iff $X$ has nonzero <a href="https://en.wikipedia.org/wiki/Signature_(topology)">signature</a>, by the <a href="https://en.wikipedia.org/wiki/Genus_of_a_multiplicative_sequence#L_genus_and_the_Hirzebruch_signature_theorem">Hirzebruch signature theorem</a>. The simplest example of a $4$-manifold with nonzero signature is $\mathbb{CP}^2$; it follows that the tangent bundle of $\mathbb{CP}^2$ does not admit a flat connection.